console
new Vue({
el: '#app',
data: {
name: 'bofa',
counter: 0,
secondCounter: 0
},
computed: {
output: function() {
return this.counter > 5 ? '大于5': '小于5';
}
},
watch: {
counter: function(value) {
var vm = this;
setTimeout(function() {
vm.counter = 0;
},2000)
}
},
methods: {
result: function() {
return this.counter > 5 ? '大于5': '小于5';
}
}
})
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js">
</script>
<div id="app">
<p>
<input type="text" v-model="name">
</p>
<p>
{{ name }}
</p>
<button v-on:click="counter++">
Increase
</button>
<button v-on:click="counter--">
Decrease
</button>
<button v-on:click="secondCounter++">
Increase Second
</button>
<p>
COnuter: {{ counter }} | {{ secondCounter }}
</p>
<p>
Result: {{ result() }} | {{ output }}
</p>
</div>