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