Vue组件通信

使用 v-on:eventName 监听事件

使用 $emit(eventName) 触发事件

HTML代码

{{total}}

javascript代码

Vue.component('button-counter', {
    template: '',
    data: function() {
        return {
            count: 0
        }
    },
    methods: {
        increment: function() {
            this.count += 1
            this.$emit('incre')
        }
    }
})
var vm = new Vue({
    el: '#app',
    data: {
        total: 0
    },
    methods: {
        incrementTotal: function() {
            this.total += 1
            this.isActive = true
        }
    }
})

你可能感兴趣的:(Vue组件通信)