【发布时间】:2019-01-12 00:47:12
【问题描述】:
我有一个包含一些项目的组件,这些项目是使用get request 方法从 api 加载的。当我点击一个项目时,我会使用动态路由重定向到它自己的页面:{ path: '/:id', component: Item }。使用currentItem() 方法识别单击的项目:currentItem() { this.items.find(item => item.code === this.$route.params.id) } 其中item.code 是我从api 获得的属性。
我的问题是,当我用当前项目刷新页面时,它不再加载。我尝试使用beforeCreate() 在他们自己的组件中再次加载项目。也许我可以使用watch 来根据项目更改状态?
beforeCreate() {
this.$http.get(url).then(response => {
this.items = response.body;
}
},
watch: {
'$route' (to, from) {
this.currentItem()
}
}
这是demo。
【问题讨论】:
标签: javascript vue.js vue-resource