axios 实现取消请求中的接口
import axios from 'axios'
export default {
data() {
return {
serverSource: ''
}
},
methods: {
getData() {
console.log('获取数据')
const serverSource = axios.CancelToken.source()
const params = {
cancelToken: serverSource.token
}
this.serverSource = serverSource
axios.get('/apis', params)
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
});
},
cleanFn() {
console.log('释放请求')
this.serverSource.cancel('cancel http')
}
}
}