vue-options-events

1.1.0 • Public • Published

vue-options-events (基于事件总线的封装)

安装

// 安装
npm i vue-options-events -S
 

引用

// 引用(eg. 在工程的main.js下)
import vueOptionsEvents from 'vue-options-events'
Vue.use(vueOptionsEvents)

Component A

// 使用例子
new Vue({
  methods: {
    show(msg) {
      console.log('show ' + msg);
    }
  },
 
 // events 对象  推荐第一种写法,es6写法
  events: {
    hi(msg) {
      console.log(msg);
    },
    // 这里直接映射到methods中的show函数
    sayHi: 'show'
  }
  
  // events 数组 第二种写法,具名函数形式
  events: [
    function hi(msg) {
      console.log(msg);
    },
    'show'  // 去methods中寻找同名函数即可
  ]
});

Component B

new Vue({
  methods: {
    show(msg) {
      this.$trigger('hi', 'hello');
      // => 'hello'
      
      this.$trigger('sayHi', 'hello');
      // this.$trigger('show', 'hello'); 数组的话,直接触发函数名字即可
      // => 'show hello'
    }
  }
});

Package Sidebar

Install

npm i vue-options-events

Weekly Downloads

0

Version

1.1.0

License

ISC

Unpacked Size

3.3 kB

Total Files

3

Last publish

Collaborators

  • haoyuenpm
  • tianjiao
  • tomastong
  • weizhongqiang
  • yangchusnheng