I'm using localforage, but I can't figure out why this.emails is not updated outside the localforage. I get no errors in console.
localforage.getItem("emails").then(function (value) {
this.emails = value
console.log(value) // shows correct value
console.log(this.emails) // shows correct value
}).catch(function (err) {
console.log(err); // no error is thrown
});
Functions have a
thisscope. So when you're settingthis.emails, you're setting the function'sthis.emailsinstead of your Vue component.You could use bind to deal with this, but the easier way would be to just use an anonymous function in your
then, like this: