<!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="js/vue.js"></script>
<style>
#app{
width: 300px;
height: 200px;
border: 1px solid silver;
}
</style>
</head>
<body>
<div id="app">
<h1>简单的加法计算器</h1>
数值A:<input type="number" v-model="num1"><br>
数值B:<input type="number" v-model="num2"><br>
<button @click="count">计算</button><br>
计算结果:{{ sum }}
</div>
<script>
new Vue({
el:"#app",
data:{
num1:'',
num2:'',
sum:''
},
methods: {
count:function(){
if(this.num1 =='' || this.num2 =='' ){
alert("请输入数字");
}else{
alert("123");
this.sum =parseInt(this.num1)+parseInt(this.num2);
}
}
}
})
</script>
</body>
</html>