1 module.exports = { 2 assetsDir: 'static', 3 parallel: false, 4 publicPath: './',//history模式注釋掉此行,hash模式需要 5 6 productionSourceMap: false, 7 devServer: { 8 port: 8081, 9 open: false, 10 overlay: { 11 warnings: false, 12 errors: true 13 }, 14 proxy: { 18 '/api': { 19 target: 'http://10.1.1.1/', //后台接口地址 20 changOrigin: true, //允許跨域 21 pathRewrite: { 22 /* 重寫路徑,當我們在瀏覽器中看到請求的地址為:http://localhost:8080/api/core/getData/userInfo 時 23 實際上訪問的地址是:http://121.121.67.254:8185/core/getData/userInfo,因為重寫了 /api 24 */ 25 '^/api': '' 26 } 27 }, 28 } 29 }, 30 }
接口公共配置
const service = axios.create({ // 公共接口--這里注意后面會講 baseURL: process.env.VUE_APP_BASE_API, // 超時時間 單位是ms,這里設置了3s的超時時間 timeout: 300 * 1000, withCredentials: true })
環境配置:
1.本地 .env.development (這里配合使用代理)
VUE_APP_BASE_API = '/api'
2.線上 .env.production
VUE_APP_BASE_API = 'http://xxx'
# 后台接口地址