Cli*_*een 0 vue.js vue-component vuejs2
我熟悉通过总线在事件上发送数据,这些工作很好,但现在我想要发出一些东西,但我没有事件可以将它绑定.
我试图在挂载时发出它但是没有如下工作:
mounted(){
bus.$emit('send-test', this.test);
},
Run Code Online (Sandbox Code Playgroud)
当您添加的事件处理程序的父母的 mounted
生命周期事件是在发射事件的孩子的 mounted
事件,因为添加了处理程序处理程序不会赶上由孩子发出该事件后,孩子已经发出该事件.基本上事件的循环是这样的.
显然,还会发生其他生命周期事件,但这是在这种情况下重要的序列.
如果要处理子项中发出的事件,则需要在子事件之前创建处理程序(调用$ on)mounted
.
$nextTick也可能有用,它解决了我的一个问题,可以这样使用
async mounted() {
await this.$nextTick()
// Code that will run only after the entire view has been rendered
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2983 次 |
最近记录: |