javascript - vue2.0 subcomponent uses $parent.$emit and $on to communicate with the parent component and reports an error?
仅有的幸福
仅有的幸福 2017-05-19 10:32:24
0
1
703


This is a subcomponent

This is the parent component

Since vue2.0 has abandoned the events attribute, how do click events in my child component bubble up to the parent component, and when should the parent component listen to this event and trigger it.
I try to pass this.$parent.$emit('function','value') under the click event of the child component,
Then pass this.$on("click" in the created hook of the parent component ,function(value){...}),
The method in methods function(value){console.log(value);}
But when an error is reported on the page, the function can be realized, but the data does not change. , so I’m asking for help from a master who has used vue2.0. I’ve been stuck here for a long time.

仅有的幸福
仅有的幸福

reply all(1)
为情所困

vue2
Use $on(eventName) to listen for events $on(eventName) 监听事件
使用 $emit(eventNameUse $emit(eventName) to trigger events
For example:
Subcomponent

methods: {
     this.$emit('fn', 'value')
}

Parent component

<ratingselect v-on:fn="type">

</ratingselect>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!