vue路由只变化参数页面组件不更新问题

时间:2018-11-16 23:31:26 类型:vue
字号:    

vue路由只变化参数页面组件不更新问题, 例如:

http://localhost:8080/web.html?classid=36

http://localhost:8080/web.html?classid=37

http://localhost:8080/web.html?classid=38


解决办法:

使用watch监听路由$route对象属性的变化

watch: {
		  '$route':function(to, from) {
		  	this.classid = this.$route.query.classid;
		    //请求接口数据开始
	    	this.$http.post("http://ncyateng.cn/api/web",
	    		{classid:this.$route.query.classid},
	    		{emulateJSON:true})
	    	    .then((response)=>{
	    		  console.log(response.data);
			      this.classid = response.data.classid;
			    })
			//请求接品数据结束
		  }
		}