Yap*_*owe 14 javascript vue.js vue-router vuejs2
我正在使用Vue 2.0-rc.6(目前最新)和Vue-router 2.0-rc.5(目前最新).
我尝试在我this.$emit('custom-event')的一个路由器组件中,this.$on('custom-event', () => { console.log('I heard an event') })在我的Vue实例中,但事件没有被监听.路由器组件本身正在听取事件但不是Vue实例.
任何的想法?
看看这个jsfiddle.
Dan*_*liz 19
来自$ emit的事件不会传播到父实例.父级必须在模板中的组件上主动监听它
<router-view @eventname="callbackMethod">
Run Code Online (Sandbox Code Playgroud)
Yap*_*owe 11
感谢LinusBorg在http://forum.vuejs.org/topic/5235/vue-2-0-instance-is-not-hearing-events-emitted-by-vue-router-components/2中指出来自$ emit的事件不会传播到父实例.
通过使用LinusBorg建议的解决方案,我没有使它工作.相反,我通过这样做了this.$router.app.$emit('eventname')
| 归档时间: |
|
| 查看次数: |
7473 次 |
| 最近记录: |