methods:{cancelRequest(){if(typeof this.source === 'function'){this.source('终止请求')}}},watch:{message(newVal){/* 防止多次触发 */// clearTimeout()// setTimeout()var that = this;this.cancelRequest();this.axios.get("/api/searchList?cityId=10&kw="+newVal,{cancelToken: new this.axios.CancelToken(function(c) {console.log(1);that.source = c;})}).then((res)=>{// console.log(res.data.data.movies)var msg = res.data.msg;var movies = res.data.data.movies;if(msg && movies){this.moviesList = res.data.data.movies.list;}}).catch((err) => {if (this.axios.isCancel(err)) {console.log('Rquest canceled', err.message); //请求如果被取消,这里是返回取消的message} else {//handle errorconsole.log(err);}})}}
