Last active
January 21, 2021 13:38
-
-
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
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
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