A:
:localStorage.setItem("articles", JSON.stringify(articles))
B:
computed: {
...mapState([
"articles"
])
},
created(){
var currentId = parseInt(this.$route.query.id);
this.currentArticle = this.articles.filter((item)=>{
return item.id === currentId
});
this.isCollected = this.currentArticle[0].isCollected;
this.collectNum = this.currentArticle[0].collectNum;
console.log(this.currentArticle)
},
vuex:
state.js: articles:localStorage["articles"]?JSON.parse(localStorage["articles"]): []
after entering component A, call the API, request the data back, save it in localStorage, click the route to jump to component B, why is this.articles [] in created (), there is no data on the page? when I enter component B, I refresh the page again and then have the data. Is there a problem with the execution sequence of computed () and created () in it? How to solve this problem?