计算器
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<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="=" v-on:click="calculate">
<input type="text" v-model="result">
</div>
<script type="text/javascript">
var vm = new Vue({
el: '#app',
data: {
n1: 0,
n2: 0,
result: 0,
opt: '-'
},
methods: {
calculate() {
if (this.opt == '+')
this.result = this.n1 + this.n2
if (this.opt == '-')
this.result = this.n1 - this.n2
if (this.opt == '*')
this.result = this.n1 * this.n2
if (this.opt == '/')
this.result = this.n1 / this.n2
}
}
});
</script>
</body>
</html>
网友评论