0.0.5 • Published 5 years ago

@h5plus/bus v0.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

bus

基于Vue的事件总线

安装

npm install @h5plus/bus --save
# or
yarn add @h5plus/bus

使用

import Vue from 'vue'
import bus from '@h5plus/bus'
Vue.use(bus)

示例

export default {
  name: 'home',
  bus: {
    // 自定义事件
    on: {
      test() {
        this.count++
        this.clg(this.count)
      }
    },
    // 自定义事件,但是只触发一次
    once: {
      onceTest(o) {
        this.msg = o.text
        this.clg(this.msg)
      }
    }
  },
  data() {
    return {
      msg: '',
      count: 0
    }
  },
  mounted() {
    // 触发总线上的事件
    this.$bus.emit('test')
    this.$bus.emit('onceTest', { text: 'onceTest abc ' + this.count })
  },
  methods: {
    clg(m = '') {
      console.log('[' + new Date().toLocaleTimeString() + '] ' + m)
    }
  }
}
0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago