简体   繁体   English

.环境变量在 Vue.js 中不起作用

[英].Environment variables don't work in Vue.js

I have.env file in the root of my project in Vue3.我在 Vue3 项目的根目录中有 .env 文件。 In the components folder, I have Card.vue and this code在 components 文件夹中,我有 Card.vue 和这段代码

console.log(process.env.FOO)

But in browser, it shows undefined.但在浏览器中,它显示未定义。

Variables must start with VUE_APP , hence变量必须以VUE_APP ,因此

`VUE_APP_FOO`

Having a similar problem here.这里有类似的问题。 I'm usnig VUE_APP_FOO to set the variable in .env but it's still undefined when console.log(process.env.VUE_APP_FOO) .我正在使用.envVUE_APP_FOO中设置变量,但在console.log(process.env.VUE_APP_FOO)时它仍然未定义。 Using Vue2 (Vue cli 4.5.11)使用 Vue2 (Vue cli 4.5.11)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM