Skip to content

Instantly share code, notes, and snippets.

@markusand
Last active January 21, 2021 13:38
Show Gist options
  • Save markusand/60423502fd5150ef2c0d11044dc4bd7b to your computer and use it in GitHub Desktop.
Save markusand/60423502fd5150ef2c0d11044dc4bd7b to your computer and use it in GitHub Desktop.
Vue.js directive to assign a confirmation to an element before triggering an action
export default {
bind(el, binding) {
const { value: { msg, callback } } = binding;
el.ask = () => {
if (confirm(msg)) callback();
};
el.addEventListener('click', el.ask);
},
unbind(el) { el.removeEventListener('click', el.ask); }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment