process报错
来源:3-16 配置环境变量封装 axios 模块
慕码人5437048
2023-06-05
这个console.log(process)会报错,process.env.VUE_APP_BASE_API中没有读出’/api’,
如果将process.env.VUE_APP_BASE_API换成’/api’就能正常运行。是目前版本不支持process了嘛?
import axios from 'axios'
console.log(process)
const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API,
timeout: 8000
})
export default service
packgage.json内容如下
{
"name": "front-center",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^1.4.0",
"core-js": "^3.8.3",
"element-plus": "^2.3.5",
"md5": "^2.3.0",
"qs": "^6.11.2",
"vue": "^3.2.13",
"vue-router": "^4.0.11",
"vuex": "^4.0.2"
},
"devDependencies": {
"@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.12.16",
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-eslint": "~5.0.0",
"@vue/cli-service": "~5.0.0",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3",
"node-sass": "^9.0.0",
"sass-loader": "^13.3.1",
"svg-sprite-loader": "^6.0.9"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "@babel/eslint-parser"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead",
"not ie 11"
]
}
写回答
1回答
-
你好
vue-cli 基于 webpack 默认就支持环境变量:https://webpack.docschina.org/guides/environment-variables/ 。process 应该是默认被配置的。可以查看下,你项目中是否包含 .env.development 文件和 .env.production 文件
032023-06-05
相似问题