I currently have something like this:
// Emit event:
<btn @click="$emit('saveJsonFile') />
// Catch event:
<Component @saveJsonFile="doSomething" />
However, I try to stay away from magic strings (events) and instead, I want to have a file with the name of events as constants.
Example:
// events.js
export const EV_SAVE_JSON_FILE = 'saveJsonFile'
And make it a global instance:
import * as EVENTS from './events.js'
Vue.prototype.$EV = EVENTS
Now I use it like this:
// Child
<btn @click="$emit($EV.EV_SAVE_JSON_FILE) />
But how to I use it on the parent? I am getting a Vue ESLint error stating that it is an invalid v-on: v:on directives dont support the modifier 'ev_save_json_file'.
// Error
<Component @[$EV.EV_SAVE_JSON_FILE]="doSomething" />
I also tried making the event constant in small caps <Component @[$ev.ev_save_json_file]="doSomething" />, but same behavior.
Help!
$EVto be available in any component instance, you should provide it as a plugin. That's why it's undefined. Your method might work if you do it before you create the app, but afterwards, mutating the prototype won't affect your instance.