1.在data里定义一个初始状态,设为false,作为加载标志
2.请求之前将状态变成true,再去请求接口,这时一直是加载状态
3.当接口响应之后不管是成功还是失败都将状态变成false
4.每次请求之前都判断一下加载状态,如果是true直接return
data() {
return {
fetching: false
}
}
,
mothods: {
request() {
if (this.fetching === true) {
return
}
this.fetching = true
axios.get(url)
.then(res => {
this.fetching = false
})
.catch(err => {
this.fetching = false
})
}
}