@h5plus/bus

0.0.5 • Public • Published

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)
    }
  }
}

Readme

Keywords

Package Sidebar

Install

npm i @h5plus/bus

Weekly Downloads

0

Version

0.0.5

License

MIT

Unpacked Size

4.19 kB

Total Files

4

Last publish

Collaborators

  • h5plus