感谢您的支持,我会继续努力的!
打开微信扫一扫,即可进行扫码打赏哦
点我查看本站打赏源码!
Powered by RUNCODEX.COM,学的不仅是技术,更是梦想!!!
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<div id="app">
<div id="counter-event-example">
<p>{{ total }}</p>
<button-counter v-on:increment="incrementTotal"></button-counter><br/>
<button-counter v-on:increment="incrementTotal"></button-counter>
</div>
xxxxxxxxxx
Vue.component('button-counter', {
template: '<div><button v-on:click="incrementHandler(1)">-</button>{{ counter }}<button v-on:click="incrementHandler(2)">+</button></div>',
data: function () {
return {
counter: 0
}
},
methods: {
incrementHandler: function (v) {
if(v==1){
this.counter -= 1
this.$emit('increment',1)
}else{
this.counter += 1
this.$emit('increment',2)
})
new Vue({
el: '#counter-event-example',
data: {
total: 0
incrementTotal: function (d) {
if(d==1){
this.total -= 1
this.total += 1
输入 CSS 代码……