Created
November 27, 2017 23:22
-
-
Save martinbean/7dc62f8bac879dfa07cd77caf5abed7a to your computer and use it in GitHub Desktop.
Vue.js confirm mixin
This file contains hidden or 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
module.exports = { | |
methods: { | |
confirm(message, callback) { | |
if (window.confirm(message)) { | |
callback(); | |
} | |
} | |
} | |
}; |
This file contains hidden or 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
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 | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Vue.js mixin that lets you execute a callback if the user confirms an action.