美文网首页
vue 中使用eventBus 传参与接收

vue 中使用eventBus 传参与接收

作者: 魔仙堡杠把子灬 | 来源:发表于2020-05-25 14:34 被阅读0次

我一直以为最伤心的一句话是我不爱你,没想到更伤心的是对不起我忘不了他!

前端QQ群: 981668406
在此附上我的QQ: 2489757828 有问题的话可以一同探讨
我的github: 李大玄
我的私人博客: 李大玄
我的简书: 李大玄

我的CSDN: 李大玄

  1. 首先创建 eventBus.js 文件
import Vue from 'vue';
export default new Vue();
  1. 传参文件
import eventBus from "@/utils/eventBus";

eventBus.$emit("selectedItemData", selectedItemData);
  1. 接收文件
mounted () { // 位置随便写
    // 接受数据 将数据赋值
    eventBus.$on('selectedItemData', (e) => {
      console.log('接受数据', e);
    })
  },

相关文章

网友评论

      本文标题:vue 中使用eventBus 传参与接收

      本文链接:https://www.haomeiwen.com/subject/azsyahtx.html