子组件传父组件依靠是事件
this.emit("父组件相应的事件",参数);事件要定义在父组件中;1、事件名称自定义;2、事件中的回调函数要定义在父组件中;3、this.emit("父组件相应的事件",参数);事件要定义在父组件中;
1、事件名称自定义;2、事件中的回调函数要定义在父组件中;3、this.emit("父组件相应的事件",参数);事件要定义在父组件中;1、事件名称自定义;2、事件中的回调函数要定义在父组件中;3、this.emit()触发事件方法


子组件传父组件应用

Vue.component("navbar",{
template:`
<div>
<button @click="handleClick()">navbar--click</button>
</div>`,
methods:{
handleClick(){
this.$emit("myevent");
}
}
})
Vue.component("sidebar",{
template:`
<div>
<ul>
<li>1111</li>
<li>1111</li>
<li>1111</li>
</ul>
</div>`
})
new Vue({
el:"#box",
data:{
isShow:false
},
methods:{
handleEvent(){
this.isShow = !this.isShow;
}
}
})


1411

被折叠的 条评论
为什么被折叠?



