https://github.com/bingxuelover/vue2-axios
封装axios,做了部分拦截
https://github.com/bingxuelover/vue2-axios
Last synced: about 2 months ago
JSON representation
封装axios,做了部分拦截
- Host: GitHub
- URL: https://github.com/bingxuelover/vue2-axios
- Owner: bingxuelover
- Created: 2021-04-10T02:53:19.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-01-08T07:08:35.000Z (5 months ago)
- Last Synced: 2025-04-12T00:05:57.686Z (about 2 months ago)
- Language: JavaScript
- Size: 51.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# vue2-axios
## 环境
"vue"
"axios",
"qs",## main.js 引用
### 引入
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import http from "./config/post";
import './utils/element-ui'
### 注册
Vue.use(http)
### 设置
- 初始化配置
http.defaultConfig.baseURL = 'https://api.example.com';
http.defaultConfig.timeout = 10000;
- 设置出错时的路由跳转
http.defaultConfig.routerChange = function () {
router.replace({
path: "/nopage",
});
};- 设置错误提示的弹出方式
http.defaultConfig.tipMessage = function(msg) {
slert(msg);
};- 设置是否判断 token,token 的错误码
http.defaultConfig.hasToken = true;//默认不判断
http.defaultConfig.tokenError = 1122;
## Vue 页面使用
this.$get("getPath", {}).then(res => { if (res.code == 200) { } });
this.$post("postPath", {}).then(res => { if (res.code == 200) { } });