vue封装http请求
import axios from 'axios'
import isObject from 'lodash/isObject'
const http = function (api, data = {}, withoutToken = false) {
const { url, method } = isObject(api) ? api : { url: api, method: 'post' }
const accessToken=localStorage.getItem('accessToken')
const platform='pc'
const v='2'
return axios({
url: withoutToken ? `${url}?platform=${platform}&v=${v}` : `${url}?accessToken=${accessToken}&platform=${platform}&v=${v}`,
method,
data,
}).catch(e => {
throw new Error('网络异常')
}).then(res => {
if(res.data.code===2001||res.data.code===2002){
this.$confirm(res.data.message[0].details, '鲸保网提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
}).then(() => {
this.$router.push({path:'/my/order/list'})
}).catch(() => {
this.$message({
type: 'info',
message: '已取消'
});
});
}else if (res.data.code === 502) {
this.$message({
message: '您现在是未登录状态,请前去登录',
type: 'warning'
});
this.$router.replace({ path: '/login' })
} else if (res.data.code == 500) {
throw new Error(res.data.message[0].details)
}
return res.data
})
}
export default http
【推荐】FlashTable:表单开发界的极速跑车,让你的开发效率一路狂飙
【推荐】Flutter适配HarmonyOS 5知识地图,实战解析+高频避坑指南
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 为什么PostgreSQL不自动缓存执行计划?
· 于是转身独立开发者
· C#.Net筑基-泛型T & 协变逆变
· dotnet 代码调试方法
· DbContext是如何识别出实体集合的
· 10亿订单如何分库分表?
· 【Cursor保姆级教程】零基础小白从安装到实战,手把手教你玩转AI编程神器!
· 如何基于three.js(webgl)引擎架构,实现3D医院、3D园区导航,3D科室路径导航
· C# 的深度强化学习框架RL_Matrix
· MySQL查询执行顺序:一张图看懂SQL是如何工作的