Skip to content

Instantly share code, notes, and snippets.

@martinbean
Created November 27, 2017 23:22
Show Gist options
  • Save martinbean/7dc62f8bac879dfa07cd77caf5abed7a to your computer and use it in GitHub Desktop.
Save martinbean/7dc62f8bac879dfa07cd77caf5abed7a to your computer and use it in GitHub Desktop.
Vue.js confirm mixin
module.exports = {
methods: {
confirm(message, callback) {
if (window.confirm(message)) {
callback();
}
}
}
};
let confirm = require('./mixins/confirm.js');
Vue.component('my-component', {
mixins: [confirm],
methods: {
onSomeEvent() {
let message = 'Are you sure you wish to do this?';
this.confirm(message, () => {
// Do something if user confirms action
});
}
}
});
@martinbean
Copy link
Author

Vue.js mixin that lets you execute a callback if the user confirms an action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment