I’m slowly marching a resonable sized project from vuejs 2 to 3, keeping with the Options API for now. The previous developer created a plugin that intercepted all emits so they could be logged every time an emit was called in a component. I’m uncertain how to translate this to vuejs 3 aside that the first parameter is now an app instance versus Vue. Here is the relevant plugin block:
function plugin (Vue, options = {}) {
...
const emit = Vue.prototype.$emit
Vue.prototype.$emit = function (...args) {
const from = this.$vnode ? this.$vnode.tag : 'Event without vnode'
if (args.length > 1) {
log.event(`Event "${args[0]}" from ${from}: `, ...args.slice(1))
} else {
log.event(`Event "${args[0]}" from ${from}`)
}
emit.apply(this, args)
}
...
My best guess is with defineEmit
, but not quite seeing it.