老师请检查,有关于等于与冒号的问题!
<!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="./vue.js"></script>
</head>
<body>
<div id="app">
<input type="text" v-model="num1">
<select v-model="opt">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">x</option>
<option value="/">÷</option>
</select>
<input type="text" v-model="num2">
<button @click="cal">=</button>
<span>{{result}}</span>
</div>
<script>
const app = {
data(){
return{
num1:"",
num2:"",
opt:"",
result:""
}
},
methods:{
cal () {
switch (this.opt) {
case '+':
this.result = parseFloat(this.num1) + parseFloat(this.num2);
break;
case '-':
this.result = parseFloat(this.num1) - parseFloat(this.num2);
break;
case '*':
this.result = parseFloat(this.num1) * parseFloat(this.num2);
break;
case '/':
this.result = parseFloat(this.num1) / parseFloat(this.num2);
break;
}
}
}
}
Vue.createApp(app).mount("#app")
</script>
</body>
</html>
有时候用冒号有时候又会用等号,很容易搞混,再数据里面是用冒号,再属性里面用等号,是这样的吗?有什么方便记忆的办法吗?
20
收起
正在回答 回答被采纳积分+1
1回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星