先把所有渲染组件涉及的方法封装到methods的一个方法里
methods:{
render(){
这里是加载各种数据的内容
this.getCourseDetail(this.$route.query.courseCode); //示例
}
}
首先组件第一次渲染会在mounted渲染一次,这个没毛病
mounted(){
this.render();
}
当使用编程式导航到当前组件时
this.$router.push({name:'',query:{key:换个值}});
用watch监听路由变化,再次执行渲染的函数
watch: {
"$route" (to, from) {
console.log(to.path);
console.log(to.query);
console.log("watch");
this.render();
}
},