Distinguish the configuration series of different access addresses in development environment, test environment, and production environment--(1) Common configuration methods

1. Create a new .env.test file in the root directory

Insert picture description here
content:

  NODE_ENV = 'test'

Second, configure the baseurl file

Insert picture description here

let baseUrl= "";   //这里是一个默认的url,可以没有
switch (process.env.NODE_ENV) {
    
    
    case 'development':
        baseUrl = "http://localhost:8080/dcxt/shop/"  //开发环境url
        break
    case 'test':   // 需要和自己配置的环境名字对应起来
        baseUrl = "https://www.baidu.com/dcxt/shop/"  //测试环境中的url
        break
    case 'production':
        baseUrl = "https://www.baidu.com/dcxt/shop/"   //生产环境url
        break
}
 
export default baseUrl;

Three, configure in the axios file

Insert picture description here

Fourth, modify the configuration of package.json

 "scripts": {
    
    
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "test": "vue-cli-service build --mode test",
    "lint": "vue-cli-service lint"
  },

In this way, the package typed out by executing npm run test is the package of the test environment

Guess you like

Origin blog.csdn.net/weixin_42349568/article/details/114266112