路由参数改变:
http://localhost:8080/?#/PerformanceReview?pid=157811552224000029
http://localhost:8080/?#/PerformanceReview?pid=157803611191800025
参数切换后,页面没刷新,数据没更新
解决方法:
监听路由变化,若参数改变,则重新加载数据,刷新页面
watch: {
'$route' (to, from) { //监听路由是否变化
if(to.query.pid != from.query.pid && to.query.pid != null){ //pid不为空才请求数据
this.pid = to.query.pid;
this.getData(); //调接口,请求数据
}
}
},
created() {
if(this.$route.query.pid === null || this.$route.query.pid === undefined) { //如pid为空,则不请求数据
this.$message.error('无指定的项目数据');
return
}
else{ //否则请求数据
this.pid = this.$route.query.pid;
this.getData();
}
},