1.1.0 • Published 5 years ago

vue-options-events v1.1.0

Weekly downloads
4
License
ISC
Repository
-
Last release
5 years ago

##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'
    }
  }
});
1.1.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago