生产与测试环境配置不同请求地址

最后更新于:2022-04-02 03:32:56

[TOC] 1. 在配置 在 `dev.env.js` 与 `prod.env.js` 中 配置域名 ```js module.exports = merge(prodEnv, { NODE_ENV: '"development"', HOST:'"http://localhost:3000"', }) ``` 在`config/index.js` ```js const host = process.env.NODE_ENV // http://localhost:3000 or http://192.168.0.1 module.exports = { apiHost:{ host:host, seller:host+"seller" //获取商户信息 }, dev: {} build:{} ``` 2. 引用 ```js const config = require('../config') //=== this.$http.get(config.apiHost.seller).then((response) => { response = response.body this.seller = response }) ``` 在axios 中配置 ``` const service = axios.create({ baseURL: process.env.BASE_API, // api 的 base_url timeout: 5000 // request timeout } ```
';