/** * 响应拦截 * @param {Object} http */ module.exports = (vm) => { uni.$u.http.interceptors.response.use((response) => { /* 对响应成功做点什么 可使用async await 做异步操作*/ const data = response.data // 自定义参数 const custom = response.config?.custom if (data.code == 200) { return res; } else if (data.code == 401) { uni.showToast({ title: 'Token失效', icon: 'none', duration: 2000 }) } else { uni.showToast({ title: data.msg, icon: 'none', duration: 2000 }) } return data.data || {} }, (response) => { return Promise.reject(response) }) }