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组件后,调用接口,请求回数据后,存到localStorage中,点击路由跳转到B组件,为什么在created()中 this.articles 为 [],页面上没有数据,当我进入B组件后再次刷新页面就有数据了,这里面的computed()和 created()是不是有执行顺序的问题?应该怎么解决这个问题呢?
相关分类