1.watch中
watch(id, (newId, oldId, onCleanup) => {
const source = axios.CancelToken.source()
axios.get(`https://xxx.xxx.com:xxx/list/id=${newId}`, {
cancelToken: source.token
})
onCleanup(() => {
//取消请求
source.cancel("请求取消")
})
})
2.在watchEffect中
watchEffect(onCleanup => {
const source = axios.CancelToken.source()
axioss.get(`https://www.xxx.com:xxx/list?id=${id}`, {
cancelToekn: source.token
})
onCleanup(() => {
source.cancel()
})
})