这个是页面获取页面的数据
methods: {
getDdtailInfo(){
axios.get('/static/mock/datail.json',{
params:{
id:this.$route.params.id
}
}).then(this.handleGetDataSucc)
},
handleGetDataSucc(res){
res=res.data
let id=this.$route.params.id
if(res.ret){
const data=res["data"+id]
this.sightName=data.sightName
this.bannerImg=data.bannerImg
this.gallaryImgs=data.gallaryImgs
this.list=data.categoryList
}
},
},
mounted () {
this.getDdtailInfo()
// console.log(this.$route.params.id);
},
这个是页面刷新,后退的时候路由发生改变重新赋值
watch: {
"$route": "getDdtailInfo",
}
这样做页面能实现效果,但是会报错
Detail.vue?97b8:49 Uncaught (in promise) TypeError: Cannot read property 'sightName' of undefined
at VueComponent.handleGetDataSucc (Detail.vue?97b8:49)
at <anonymous>
这是什么情况,handleGetDataSucc(res)这个也要用监听嘛,怎么监听