效果图
知识点
- 数据的热更新
- switch的使用
源码
index.html
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script src="../src/vue.js"></script></head><body><section id="app"><input type="number" v-model.number.lazy='addend'><select v-model='type'><option>+</option><option>-</option><option>*</option><option>/</option></select><input type="number"v-model.number.lazy='augend' ><button @click='sum'>=</button><input type="text" v-model='result'></section><script>const vm = new Vue({el:'#app',data:{addend:0,augend:0,result:'',type:'+'},methods:{sum(){let addend = this.addend;let augend = this.augend;let type = this.type;switch (type){case '+':this.result = addend + augend;break;case '-':this.result = addend - augend;break;case '*':this.result = addend * augend;break;case '/':this.result = addend / augend;break;}}}})</script></body></html>
其余代码
简易计算器.rar
