項目根目錄
新建
.env.development (開發環境)
/* 文件中的內容主要是對開發環境和生產環境的請求接口路徑做修改 */
NODE_ENV = 'development'
VUE_APP_API_URL = '/api'
.env.production (生產環境)
NODE_ENV = 'development'
VUE_APP_API_URL = 'http://'
axios
axios.defaults.baseURL = process.env.VUE_APP_API_URL,
環境切換
package.json
"scripts": {
"serve": "vue-cli-service serve",
"production-serve": "vue-cli-service serve --mode production", //這個
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
啟動項目
yarn serve
or
yarn production-serve
or
yarn build