Skip to content

Instantly share code, notes, and snippets.

@AlbinoDrought
Last active August 7, 2018 17:42
Show Gist options
  • Save AlbinoDrought/94b54aeacf44673fe88c46a98b3f6802 to your computer and use it in GitHub Desktop.
Save AlbinoDrought/94b54aeacf44673fe88c46a98b3f6802 to your computer and use it in GitHub Desktop.
Vue event-bubbling directive
/**
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