Set data object to value from Promise in Vue 3 Set data object to value from Promise in Vue 3 vue.js vue.js

Set data object to value from Promise in Vue 3


this get the window reference as you are using dynamic scope, use lexical scope binding to get this as Vue

For your specific reference and eagerness to read more about scopes - follow this Static (Lexical) Scoping vs Dynamic Scoping (Pseudocode)

For lexically binding use arrow-function

loadPosts() {  stories = getPosts();   stories.then(response => {      this.posts = response.posts;      console.log(response.posts[0].title); // "My Post Title"  }); }