赞
踩
config/dev.env.js:
- const merges = require('webpack-merge');
- const prodEnv = require('./prod.env');
-
- module.exports = merges(prodEnv, {
- NODE_ENV: 'development',
- APP_NAME: '****',
- API_ROOT: '"https://xxx.xxx.xxx.xx:xxxx"'
- });
config/prod.env.js:
- module.exports = {
- NODE_ENV: 'production',
- APP_NAME: '*********',
- API_ROOT: 'http://xxx.xxx.xxx.xx:xxxx'
- };
axios/index.js:
- import axios from 'axios'
- import store from '../store'
- import router from '../router'
- import Vue from 'vue';
- let v = new Vue();
- let _this = this;
- var repeatUrl = ""//防止重复提交
-
- const http = axios.create({
- timeout: 10000 * 12,
- baseURL: process.env.API_ROOT, //地址1
- headers: {
- 'X-Requested-With': 'XMLHttpRequest'
- }
- })
- const http1 = axios.create({
- timeout: 10000 * 12,
- baseURL: "http://ss.sss.s.ss:ssss", //地址2
- headers: {
- 'X-Requested-With': 'XMLHttpRequest'
- }
- })
-
- http.interceptors.request.use(
- config => {return config},
- error => { return Promise.reject(error)}
- );
-
- http1.interceptors.request.use(config => {
- return config;
- }, error => {
- return Promise.reject(error);
- });
-
- http.interceptors.response.use(response => {
- return response;
- },
- error => {}
- );
-
- http1.interceptors.response.use(response => {
- return response;
- },
- error => {}
- );
-
- export {http, http1}
main.js:
- import {http} from './axios'
- import {http1} from './axios'
-
- Vue.prototype.$http = http
- Vue.prototype.$http1 = http1
- //使用地址1请求:
- this.$http.get(`${this.urlType}/toCheck`).then((res) => {})
- //使用地址2请求:
- this.$http1.get(`${this.urlType}/toCheck`).then((res) => {})
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。