本文实例讲述了vue数据操作之点击事件实现num加减功能。分享给大家供大家参考,具体如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue num加减</title>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="app">
<button v-on:click="add(10)">click me</button>
<button v-on:click="remove(5)">click me</button>
<button v-on:click="num++">click me</button>
<button v-on:click="num--">click me</button>
<span>{{num}}</span>
</div>
<script>
new Vue({
el: '#app',
data: {
num:0,
message: '6',
data: {
name: '',
gender: '',
interest: [],
identity: ''
},
selected: 'A',
options: [
{ text: 'One', value: 'A' },
{ text: 'Two', value: 'B' },
{ text: 'Three', value: 'C' }
]
},
methods:{
add:function (inc){
this.num += inc;
},
remove:function (dec){
this.num -= dec;
},
}
})
</script>
</body>
</html>
这里使用在线HTML/CSS/JavaScript代码运行工具:http://tools.jb51.net/code/HtmlJsRun测试上述代码,可得如下运行结果:
希望本文所述对大家vue.js程序设计有所帮助。