統一封裝 Axios 介面與異常處理

2021-09-19 12:17:22 字數 1234 閱讀 1462

vue.config.js:

// vue.config.js 配置說明

// 這裡只列一部分,具體配置慘考文件:

module.exports = 3個屬性host,port,https

// 它支援webpack-dev-server的所有選項

devserver:

open: false, //配置自動啟動瀏覽器

proxy: '' // 配置跨域處理,只有乙個**

// proxy: // 配置多個**

axios.js

import axios from 'axios'

// import qs from 'qs'

// axios.defaults.baseurl = process.env.node_env === "production" ? "/" : "/spring-boot-vue";

axios.defaults.baseurl = "/spring-boot-vue";

axios.defaults.timeout = 10000;

// 響應***

axios.interceptors.response.use(

response => else else url [請求的url位址]

* @param params [請求時攜帶的引數]

export function get(url, params) ).then(res => ).catch(err => url [請求的url位址]

* @param params [請求時攜帶的引數]

export function post(url, params) from '@/axios'

export const apiaddress = p => post('test', p);

export const apiaddressget = p => get('test1', p);

export const apiaddressget1 = indexcode => get('test2/'+indexcode, {});

home.js

var param = ;

apiaddress(param, result =>

public baseresult test1(user user)

public baseresult test2(@pathvariable string indexcode)

}

golang db事務的統一封裝

database db.db tx,err database.begin if err nil stmt,err tx.prepare sqlquery if err nil err stmt.exec paras.if err nil err tx.commit if err nil以上是我們使用...

vue 請求統一封裝和呼叫

1.request.js統一封裝的請求介面 author your name date 2020 03 20 14 17 34 lastedittime 2020 03 26 11 27 50 lasteditors your name description in user settings ed...

axios封裝統一處理介面

檔案位置 檔案request.js request.js import axios from axios import store from store import router from router import from config ssourl import from element u...