无法在 .env 文件 vue cli 3 中指定 url

Cannot specify url in .env file vue cli 3

我指的是 vue cli 3 中的 documentation about environment variables

我可以设置它并显示简单的变量,但是我在 .env 文件中的 url 没有显示。

.env 文件的内容:

FOO=bar
VUE_APP_SECRET=secret
API_URL="https://staging.something.org"

这是我查看环境的方式:

console.log(process.env)
BASE_URL: "/"
NODE_ENV: "development"
VUE_APP_SECRET: "secret"

API_URL 不可见,我是不是做错了什么?

参考documentation.

Only variables that start with VUE_APP_ will be statically embedded into the client bundle with webpack.DefinePlugin. You can access them in your application code:

您的 VUE_APP_SECRET 可以访问,因为它的前缀是 VUE_APP_。使用 VUE_APP_API_URL 而不是 API_URL 在您的前端访问它。

从 CLI 3 开始,Vue 仅在添加前缀 VUE_APP_

时才识别 dotenv 中的变量

进行更改时,重新启动 CLI。