共计 759 个字符,预计需要花费 2 分钟才能阅读完成。
// ajax
var Fly = require('./plugins/tools/fly.js');
var fly = new Fly
//添加请求拦截器
fly.interceptors.request.use((config,promise)=>{
if (!config.body.noLoading) {
// #ifndef APP-PLUS
uni.showLoading({
// title:'loading...',
mask: false
})
// #endif
// #ifdef APP-PLUS
plus.nativeUI.showWaiting('');
// #endif
}
return config;
})
//添加响应拦截器,响应拦截器会在then/catch处理之前执行
fly.interceptors.response.use(
(response,promise) => {
//只将请求结果的data字段返回
// #ifndef APP-PLUS
uni.hideLoading()
// #endif
// #ifdef APP-PLUS
plus.nativeUI.closeWaiting();
// #endif
return response.data
},
(err,promise) => {
//发生网络错误后会走到这里
//promise.resolve("ssss")
// #ifndef APP-PLUS
uni.showToast({
title: '网络连接出现问题,请刷新或稍后再试',
icon: 'none',
mask: true,
duration: 2000
});
// #endif
// #ifdef APP-PLUS
plus.nativeUI.toast('网络连接出现问题,请刷新或稍后再试');
// #endif
}
)
Vue.prototype.$request = fly;
正文完