路由参数改变,页面数据不更新解决方法:

http://localhost:8080/#test?id=1

http://localhost:8080/#test?id=2,参数切换后,数据未更新

以下为解决办法:

监听路由变化,若参数不相同,则重新加载数据,更新视图:

watch: {
	  '$route' (to, from) { //监听路由是否变化
		  if(to.query.id != from.query.id){
			  this.id = to.query.id;
			  this.init();//重新加载数据
		  }
	  }
},
created() {
	if(this.$route.query) {
		this.id = this.$route.query.id;
		this.init();
	}
},

 

Logo

前往低代码交流专区

更多推荐