首页 > 其他 > 详细

vue组件传值 part2

时间:2019-11-27 19:21:06      阅读:62      评论:0      收藏:0      [点我收藏+]

非父子组件传值

轻量级 视图层框架

复杂组件间传值,引进其他的工具或者设计模式

1.vuex

2.总线机制

//main line

1.在main.js中注册全局的bus 

Vue.prototype.bus=new Vue();

2.在组建中使用

   子组建使用:this.bus.$emit(‘自定义事件名‘,data)

methods:{
        handleClicks(){
        this.bus.$emit(‘openMenu‘,true)
       }
}

父组建使用:  this.bus.$on("自定义事件名", msg => {})

mounted() {
    this.bus.$on("openMenu", msg => {
    this.show = msg;
   });

}

 

vue组件传值 part2

原文:https://www.cnblogs.com/-constructor/p/11944538.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!