<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="./vue.js"></script> </head> <body> <div id="app"> <input type="text" v-model.number="num1" /> <select v-model="type"> <option value="+">+</option> <option value="-">-</option> <option value="*">*</option> <option value="/">-</option> </select> <input type="text" v-model .number="num2" /> <button @click="handleclick">=</button> <span>{ { result}}</span> </div> <script> const vm = new Vue({
el: '#app', data: {
num1: 0,
num2: 0,
type: '+',
result: 0
}, methods: {
handleclick() {
const { type, num1, num2 } = this; switch (type) {
case '+':
this.result = num1 + num2;
break;
case '-':
this.result = num1 - num2;
break;
case '*':
this.result = num1 * num2;
break;
case '/':
this.result = num1 / num2;
break;
}
}
}
})
</script>
</body>
</html>
还没有评论,来说两句吧...