vue bus传值(带参数),调用组件之间的方法

1.不带参数的调用
创建的时候绑定
  created () {
    this.getLeftF();
    this.$bus.on('getLeftF', this.getLeftF);
  },
  销毁
  beforeDestroy () {
    this.$bus.off('getLeftF');  
  },
  methods: {
	  getLeftF () {
	      let params = {code: '0', page: 1, size: 50, companyId: this.companyId};
	      FIND_PAGE_DESIGN_MODULEE(params).then(res => {
	        if (res.code === 200 && res.data.data.length > 0) {
	          this.leftMenus = res.data.data;
	          this.$emit('update:leftMenus', this.leftMenus);
	          this.auotoAdd(res.data.data);
	        }
	      });
	    },
}

想要调用的地方直接this.$bus.emit('getLeftF'); 就可以了

2.带参数的调用

  created () {
    this.initTag();
    this.$bus.on('updateTopTags', this.updateTopTags);
  },
  beforeDestroy () {
    this.$bus.off('updateTopTags');
  },
  methods: {
	updateTopTags (newVal) {
	      console.log('qqqqq导航栏点击了', this.tags);
	      if (newVal.type === this.activeTag.type && newVal.sourceId === this.activeTag.sourceId) {
	        console.log('qqqqq已经是当前数据,不用切换');
	      } else {
	        if (!this.checkAddOrChange(newVal)) {
	          this.tags.push(newVal);
	        }
	        this.activeTag = newVal;
	      }
	    },
	}
想要调用的地方直接this.$bus.emit('updateTopTags', getObj); 就可以了

版权声明:本文为weixin_39701533原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。