I am developing an application with vuejs. I want to use this inside a promise, I want to be able to call a function or data inside the .then scope, and for that I use the this. But if I do this inside the .then I get an error, it seems this to be lost even though I bind the scope with and arrow function. What can I do?
javascript
methods: {
...mapActions(['setCredentials']),
doLogin() {
console.log('credentials ' + this.username, this.password);
this.$store.dispatch('connect', {
username: this.username,
password: this.password,
});
this.checkResult().then((interval) => {
vm.$f7router.navigate('/favorites');
})
},
checkResult() {
return new Promise(function(resolve) {
var id = setInterval( () => {
let condition = this.$store.state.isConnected
if (condition) {
clearInterval(id);
resolve(id);
}
setTimeout(() => {
clearInterval(id);
reject(id);
}, 20000);
}, 10);
});
}