This undefined
sebastien-savalle opened this issue · 3 comments
Hi,
I want to use vue socketio in the confirm method of the dialog. But this is undefined in this anonymous function.
Is there any solution to bypass that ?
this.$dialog.confirm('Do you want to delete the object ?')
.then(function () {
console.log('delete object');
this.$socket.emit('delete');
})
.catch(function () {
console.log('cancel delete object');
});
Thanks a lot
I'm sorry for the late reply. I've been extremely busy lately. Are you adding the plugin via the script tag? if yes, then please see possible solution here 220fbda.
I updated the readme to window.Vue.use(VuejsDialog.default)
Maybe i misunderstood the issue at first. If the this
in this.$socket.emit('delete');
is the problem, then i will suggest you make use of the function shorthand "arrow functions" so as to expose this to the parent scope and not the function(){}
scope. Example;
this.$dialog.confirm('Do you want to delete the object ?')
.then(() => {
console.log('delete object');
this.$socket.emit('delete');
})
.catch(function () {
console.log('cancel delete object');
});
Thanks, I have solved my problem by changing the scope of the function. I forgot to close the issue.