-
-
Save ptitb/4da360e3f80b5f55e779cab3760ba156 to your computer and use it in GitHub Desktop.
Built in eventbus composable for nuxt 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// composables/useEmitter.ts | |
export default function () { | |
const hooks = useNuxtApp().hooks; | |
return { | |
emit: hooks.callHook, | |
on: hooks.hook, | |
} | |
} | |
// usage in components | |
someFunction(){ | |
const emitter = useEmitter(); | |
emitter.emit("test-emit", "hello world"); | |
} | |
// anoter components | |
const emitter = useEmitter(); | |
emitter.on("test-emit", (payload) => { | |
console.log(payload); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment