An open API service indexing awesome lists of open source software.

https://github.com/bingxuelover/vue2-axios

封装axios,做了部分拦截
https://github.com/bingxuelover/vue2-axios

Last synced: about 2 months ago
JSON representation

封装axios,做了部分拦截

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) { } });