<child-component :message="parentMessage"></child-component>
props: ['message']
this.$emit('custom-event', data)
<child-component @custom-event="handleEvent"></child-component>
this.$parent.parentMethod()
this.$children[0].childMethod()
<child-component ref="child"></child-component>
this.$refs.child.childMethod()
export const EventBus = new Vue()
EventBus.$emit('event-name', data)
EventBus.$on('event-name', (data) => {
console.log(data)
})
beforeDestroy() {
EventBus.$off('event-name')
}
provide() {
return {
theme: 'dark'
}
}
inject: ['theme']
<child-component :foo="foo" :bar="bar" @custom-event="handleEvent"></child-component>
<grand-child v-bind="$attrs" v-on="$listeners"></grand-child>
export default new Vuex.Store({
state: {
count: 0
},
mutations: {
increment(state) {
state.count++
}
}
})
this.$store.commit('increment')
console.log(this.$store.state.count)