<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./js/vue.min.js"></script>
</head>
<body>
<h1>简单计算器</h1>
<div id="app">
<div>
<span>数值A:</span>
<span> <input type="text" v-model='a'>
</span>
</div>
<div>
<span>数值B:</span>
<span> <input type="text" v-model='b'>
</span>
</div>
<button v-on:click="handle">计算</button>
<div>
<span>
计算结果:
</span>
<span v-text="result"></span>
</div>
</div>
</body>
<script>
var vm = new Vue({
el: '#app',
data: {
a: '',
b: '',
result: ''
},
methods: {
handle: function () {
this.result = parseInt(this.a) + parseInt(this.b);
}
}
})
</script>
</html>