Skip to content

sonidelav/vue3-instance-events

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vue3 Instance Events Plugin

Adds .on and .emit into instance API

Install

NPM

npm install vue3-instance-events

Yarn

yarn add vue3-instance-events

Usage

import { VueInstanceEvents } from 'vue3-instance-events'
import { createApp } from 'vue'
import App from './App.vue'

const app = createApp(App).use(VueInstanceEvents)
const instance = app.mount('#app')

instance.on('showed', () => {
    ...
})

// Event names in camelCase
instance.emit('showComponent')

Vue Documentation

Breaking Changes v2 to v3 Migrations

We removed $on, $off and $once methods from the instance completely. $emit is still a part of the existing API as it's used to trigger event handlers declaratively attached by a parent component.