watch monitors changes in routing $route and initiates an ajax request again

watch monitors changes in routing $route and initiates an ajax request again

1. Premise

1. Some project interfaces obtain data by listening to route monitoring.
2. It troubles many friends to initiate requests again. Monitor the changes in the routing $route parameters in real time through watch, pass the latest parameters to it, and initiate ajax requests in time. 3.
watch The function is to monitor data changes from time to time. Write some functions in it to trigger them immediately while monitoring data changes.

2. Implementation

	// 通过watch监听组件$route属性 一旦发生变化就执行下方语句
	watch:{
    
    
		$route:{
    
    
			handler(newValue,oldValue){
    
    
				// 能够获取到最新的路由参数,合并到Objectname中
				Object.assign(this.Objectname,this.$route.query,this.$route.params)
				// 进行ajax请求数据
				this.getsearchlist()
				//分类名字与关键字不用清理:因为每一次路由发生变化的时候,都会给他赋予新的数据
				this.Objectname.category1Id=""
				this.Objectname.category2Id=""
				this.Objectname.category3Id=""

			},
			deep:true
		}
	}

Guess you like

Origin blog.csdn.net/m0_62496369/article/details/127841543