vue设置一个简单的计算器
生活随笔
收集整理的這篇文章主要介紹了
vue设置一个简单的计算器
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
vue設(shè)置一個(gè)簡(jiǎn)單的計(jì)算器
<div id="app"><input type="text" v-model="n1"><select v-model="opt"><option value="+">+</option><option value="-">-</option><option value="*">*</option><option value="/">/</option></select><input type="text" v-model="n2"><input type="button" value="="><input type="text" v-model="result"><el-button @click="calc">計(jì)算</el-button> </div> data(){// 計(jì)算器n1: 0,n2: 0,result: 0,opt: '+' }methods:{ // 計(jì)算器calc() {switch (this.opt) {case "+":this.result = parseInt(this.n1) + parseInt(this.n2);break;case "-":this.result = parseInt(this.n1) - parseInt(this.n2);break;case "*":this.result = parseInt(this.n1) * parseInt(this.n2);break;case "/":this.result = parseInt(this.n1) / parseInt(this.n2);break;}} }效果圖:
總結(jié)
以上是生活随笔為你收集整理的vue设置一个简单的计算器的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Java】ArrayList 列表的泛
- 下一篇: export default 和 exp