console.log(JSON.stringify(error));//console : Error: Request failed with status code 402 return Promise.reject(error.response.data) }); /*{ type:type, params:params, }*/ // 封装请求 export function fetch (url, options) { var opt = options || {} return new Promise((resolve, reject...
console.log(JSON.stringify(error));//console : Error: Request failed with status code 402 return Promise.reject(error.response.data) }); /*{ type:type, params:params, }*/ // 封装请求 export function fetch (url, options) { var opt = options || {} return new Promise((resolve, reject...
}elseif(message.includes("Request failed with status code")) { message ="系统接口"+ message.substr(message.length -3) +"异常"; } ElMessage({message: message,type:'error',duration:3*1000})returnPromise.reject(error) } )exportdefaultservice 可以从上面看到,在网络请求的时候如果返回401时,做了...
}elseif(message.includes('Request failed with status code')) { message ='系统接口'+ message.substr(message.length -3) +'异常'; } ElMessage({ message: message, type:'error', }); router.push('/login'); returnPromise.reject(error); } ); exportdefaultservice; 相关请求接口统一写在api目录...
else if (message.includes("Request failed with status code")) { message = "系统接口" + message.substr(message.length - 3) + "异常"; } ElMessage({ message: message, type: 'error', duration: 5 * 1000 }) return Promise.reject(error) ...
}catch(error) {console.error('Error in request api agents', error);if(error.response&& error.response.status===401|| error.code=='ERR_NETWORK'|| error.code=='ERR_CONNECTION_REFUSED') {this.logout(); } } } }, And here is how I'm managing it in my template script:...
handler.codeHandler(res.data?.code, res.data?.msg) } return res.data?.data }, responseInterceptorCatch: (err) => { // console.log('===响应失败的拦截===') if (err.config?.mock) return mock.request(err.config) handler.codeHandler(err?.response?.status, err.message) throw err }, ...
最近菜鸟自己搭建一个项目,想着vue3都出来这么久了,再不用 vue3,怕是等我熟悉 vue3 的时候,vue4 都出来了,直接落后时代一个大版本那就难受了! 但是突然从vue2转变到用这个 vue3 确实是让人脑壳疼,接下来就把菜鸟踩坑的地方都分享给大家了! 创建项目 + eslint + prettier ...
config.headers['request-id']= uuid(); 响应拦截器 处理响应码const code = res.data.code || 200; 指定超时时间: timeout: 10000 接口使用 user/index.js import { changeUserStatus, listUser, resetUserPwd, delUser, getUser, updateUser, addUser,exportXlsUrl,importTemplateUrl } from "@/api/syste...
(res.config)// 未设置状态码则默认成功状态constcode=res.data['code']||200;// 获取错误信息letmsg=res.data['msg']||""switch(code){case"401":msg='认证失败,无法访问系统资源'break;case"403":msg='当前操作没有权限'break;case"404":msg='访问资源不存在'break;case"default":msg='系统未知...