0.1.1 • Published 1 year ago

vue-pubsub v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Vue Pubsub

A Pubsub Plugin (or better Event Bus) for Vue, inspired in mitt

Use

npm i vue-pubsub

import { createApp } from "vue";
import { PubsubPlugin } from "vue-pubsub";
import App from "./App.vue";

const app = createApp(App);

app.use(PubsubPlugin());
app.mount("#app");

// ...

<script setup>
import { usePubsub } from "vue-pubsub";

const pubsub = usePubsub();

pubsub.on("test", (data) => {
  console.log(data);
});
</script>

// in other .vue file / setup hook
pubsub.to("test", "Hello World!");

Using with Typescript

You can declare custom channel types by:

declare module "vue-pubsub" {
  interface Channels {
    test: string;
  }
}

Vue inject() and provide() do not support generic types in same context. Better suggestions for this are welcome.

0.1.1

1 year ago

0.1.0

1 year ago