How do you emit an event from a nuxt plugin?

前端 未结 3 1950
傲寒
傲寒 2021-01-18 19:19

I am creating a plugin that will emit basic nuxt events triggered by sockets. The nuxt event will then be recieved and open a snackbar. When inside a component it is easy to

3条回答
  •  孤独总比滥情好
    2021-01-18 19:29

    You can use something like this in your plugin.js file, what the plugin will do is use window.$nuxt.$emit which is available on the client side

    export default function (context) {
        $nuxt.$emit('event-to-emit')
    }
    

提交回复
热议问题