父组件:
methods:{
getName(name){
console.log("学生名:",name)
}
}
mounted(){
//当自定义事件sName被触发时
this.$refs.student.$on('sName',this.getName)
}
子组件:
methods:{
sendName(){
this.$emit("sName",this.name)
}
unbind(){
this.$off('sName') //解绑一个
this.$off(['sName','demo']) //解绑多个
this.$off() //所有自定义事件全部解绑
}
death(){
this.$destroy()
//销毁当前组件的实例,销毁后所有student组件实例的自定义事件全都不奏效
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)