Skip to content

tachibana-shin/vue-bus3

Repository files navigation

vue-bus3

A package project View docs

Build NPM

Vs mitt

  • automatically cancel all events listened to at the component before the component is destroyed
  • memory saver and clear for javascript garbage collector
  • composition api support

Installation

NPM / Yarn:

yarn add vue-bus3

CDN:

<script src="https://unpkg.com/vue-bus3"></script>

Example

main.ts

// your example
import { createBus } from "vue-bus3";

const bus = createBus<{
  "hide-comment": void
}>

app.use(bus);

App.vue

import { useBus } from "vue-bus3"

const bus = useBus()

bus.on("hide-comment", () => {
    console.log("hide-comment")
})

bus.emit("hide-comment")

Declare event types

bus.d.ts

import "vue-bus3"

declare module "vue-bus3" {
    interface TypeEventsGlobal {
        "hide-comment": void
    }
}