<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="vue.js"></script>
</head>
<body>
<div id="app">
<input type="text" v-model="num1" @keyup="compute">
<span>+</span>
<input type="text" v-model="num2" @keyup="compute">
<span>=</span>
<input type="text" value="num3" v-model="num3">
<input type="button" value="reset" @click="reset">
</div>
</body>
<script>
let comp=new Vue({
el:"#app",
data:{
num1:'',
num2:'',
num3:'',
},
methods:{
compute(){
this.num3=Number(this.num1)+Number(this.num2);
},
reset(){
this.num1='';
this.num2='';
this.num3='';
}
}
});
</script>
</html>
【vue.js】自动计算(加法)小demo
最新推荐文章于 2024-09-13 22:50:15 发布