-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emit event from page to layout #8122
Comments
@steveDL Can you clarify what the use case for this might be? Just off top I'd imagine that there might be a different way to achieve the end goal you are looking for. |
I actually tried to do this and found that the global event bus was actually what I was looking for. Simply do
in any component (as opposed to and listen to it in any component (and also in your
|
Thanks for your contribution to Nuxt.js!
Issues that are labeled as |
This is amazing. Nuxt has a global event bus?! I didn't know this, only been using Nuxt for 3 years... |
This is awesome! thanks @tbrannt ! 🙏 |
It's strange that this works with I can even see the listener on This solution may be good enough tho, thanks ! |
Is there a way to do this using @nuxtjs/composition-api? |
Thanks, Helpfull ! |
How could this be tackled with @nuxtjs/composition-api? |
I'm not very good at typescript and nuxt, but you can make this reference
import { getCurrentInstance } from '@nuxtjs/composition-api'
export const useNuxt = () => {
const instance = getCurrentInstance()
return (instance as { proxy: Vue }).proxy.$nuxt
}
import { useNuxt } from '~/composables/use-nuxt'
const $nuxt = useNuxt()
onMounted(() => $nuxt.$on('test', () => alert('test')))
import { useNuxt } from '~/composables/use-nuxt'
const $nuxt = useNuxt()
$nuxt.$emit('test') |
I tried the approach from the latest comment but it does not work anymore: function I find it inconvenient overall, that existing functions get removed from the new version of the framework. This approach creates headache for the users of the framework |
what version did you try it on? |
Same here, I'm also unable to access |
The global event bus got removed in vue 3, here's the migration guide : In most circumstances, using a global event bus for communicating between components is discouraged. While it is often the simplest solution in the short term, it almost invariably proves to be a maintenance headache in the long term. Depending on the circumstances, there are various alternatives to using an event bus:
If you really need to implement something with an event bus, I would recommend mitt. |
Is it possible to emit an event from a page back up to default.vue layout?
<nuxt @loading="loadingHandler" />
The text was updated successfully, but these errors were encountered: