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"]): []進入A組件后,調(diào)用接口,請求回數(shù)據(jù)后,存到localStorage中,點擊路由跳轉到B組件,為什么在created()中 this.articles 為 [],頁面上沒有數(shù)據(jù),當我進入B組件后再次刷新頁面就有數(shù)據(jù)了,這里面的computed()和 created()是不是有執(zhí)行順序的問題?應該怎么解決這個問題呢?
添加回答
舉報
0/150
提交
取消