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!
question from:
https://stackoverflow.com/questions/65895588/using-vue-prototypes-for-custom-event 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…