1.在请求文件同层目录新建config 目录
const env = process.env.NODE_ENV
const config = {
development: {
baseURL: '/api', //开发
},
production: {
baseURL: '/', //生产
},
}
export default {
baseURL: config[env].baseURL,
}
2.在请求接口引入文件
import config from './config/index'
let ConfigBaseURL = config.baseURL //根地址
const http = axios.create({
timeout: 15000,
baseURL: ConfigBaseURL,
})
http.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
网友评论