Skip to content

Instantly share code, notes, and snippets.

@cursosdesarrolloweb
Last active Jan 13, 2021
Embed
What would you like to do?
<template>
<h1>Blog</h1>
<button @click="globalEvent">Global Event</button>
</template>
<script>
import { inject } from "vue";
export default {
name: "Blog",
setup() {
const emitter = inject("emitter")
const globalEvent = () => {
emitter.emit("blogLoaded", true)
}
return { globalEvent };
}
}
</script>
<template>
<h1>Products</h1>
</template>
<script>
import { inject, onMounted } from "vue";
export default {
name: "Products",
setup() {
const emitter = inject("emitter")
onMounted(() => {
emitter.on("blogLoaded", (status) => {
console.log("blog loaded")
console.log(status)
})
})
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment