关于ajax处理请求的思考
//url白名单
var isInWhiteList = function (url) {
var flag = false
whiteList.forEach((v, i) => {
if (url.indexOf(v) >= 0) {
flag = true
}
})
return flag
}
/**
* http拦截处理
* @param config
* @returns {*}
*/
export const request = function (config) {
// console.log(config.url)
if (!isInWhiteList(config.url)) {
wuage.openToast({
message: '加载中...',
duration: 10000,
zindex: 1,
icon: 'loading'
})
}
// loadingTimer = setTimeout(function () {
// wuage.openToast({
// message: '连接超时',
// duration: 5000,
// zindex: 1,
// icon: 'error'
// })
// },10000)
return config
}
export const response = function (response) {
clearTimeout(loadingTimer)
loadingTimer = setTimeout(function () {
wuage.closeToast();
clearTimeout(loadingTimer)
},300)
return response
}
交互处理!