Last active
August 7, 2018 17:42
-
-
Save AlbinoDrought/94b54aeacf44673fe88c46a98b3f6802 to your computer and use it in GitHub Desktop.
Vue event-bubbling directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
v-bubble directive | |
Usage: | |
- v-bubble:eventName | |
- v-bubble:eventName="newEventName" | |
Examples: | |
- v-bubble:input is equivalent to @input="val => { $emit('input', val) }" | |
- v-bubble:input="select" is equivalent to @input="val => { $emit('select', val) }" | |
*/ | |
export default (Vue) => { | |
Vue.directive('bubble', { | |
bind: (el, { arg, value = null }, vnode) => { | |
vnode.componentInstance.$on(arg, (...args) => { | |
vnode.context.$emit(value === null ? arg : value, ...args); | |
}); | |
}, | |
}); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment