Axios 配置
配置 baseURL , 在不同开发环境下对接不同后端接口
axios.defaults.baseURL = 'https://example.com'
配置拦截器
请求拦截器
axios.interceptors.request.use()
响应拦截器
axios.interceptors.response.use()
main.js
import Vue from 'vue' import App from './App.vue' import axios from 'axios' import VueAxios from 'vue-axios' if (process.env.NODE_ENV === 'development') { // require('./mock.js') axios.defaults.baseURL = 'https://example.com' } axios.defaults.withCredentials = true axios.interceptors.request.use(function (config) { return config }, function (error) { return Promise.reject(error) }) axios.interceptors.response.use(function (response) { console.log(3) return response }, function (error) { console.log(4) return Promise.reject(error) }) Vue.use(VueAxios, axios) new Vue({ render: h => h(App) }).$mount('#app')
相关链接: