Event Bus 在Vue中的使用

作者: 蘇上方 | 来源:发表于2017-04-14 10:51 被阅读955次
// bus.js
export default new Vue();
使用on全局监听
import Bus from '../bus.js';

export default {
  ready() {
    Bus.$on('loadSuccess', text => {
      this.show = true;
      this.status = 'loadSuccess'
      if (text) {
        this.text = text;
      }
    })
  },
}
使用$emit触发事件。
ajax({
  url: Config.API_ADDRESS_ADD,
  type: 'post',
  dataType: 'json',
  data: data
}).then((data)=>{
    Bus.$emit('loadSuccess', '添加成功!');
}).catch((data)=> {
})

相关文章

  • vue文档集合

    Vue2使用笔记3--父子组件的通信Vue 2.0开发实践(组件间通讯)Event Bus 在Vue中的使用vue...

  • Event Bus 在Vue中的使用

    使用on全局监听 使用$emit触发事件。

  • 2019-12-13

    vue-bus的使用 1.安装:npminstall vue-bus 2.使用:在main.js中 importV...

  • Vue Event Bus

    问题陈述 我有两个组成部分。我将数据从一个组件传递到另一个组件。接收方应显示接收的数据 创建新的Vue应用程序 要...

  • 71.在单独的js文件中使用vue插件里面的方法

    1.event-bus.js vue插件 2.main.js 3.在router/index.js

  • Vue3 使用 Event Bus

    本文已整理到 Github,地址 ? blog[https://github.com/lio-zero/blog]...

  • 短信发送 guava event bus 方式

    感觉 event bus简单实用,使用 event bus 做一个demo 如下: 配置文件 短信配置文件 发送短...

  • Vue - 兄弟组件传值

    1. 使用中间Vue实例实现兄弟传值。 创建一个用于转发数据的中间Vue实例bus 在子组件1中使用bus.$em...

  • vue组件传值

    vue中的参数传递方式有1、父子组件中通过props,$emit互相传递2、event bus事件总线3、vuex...

  • global event bus Vue

    1.新建bus.js 2.App.vue里created方法里定义事件 3.Test.vue组件内调用

网友评论

本文标题:Event Bus 在Vue中的使用

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