如何在 Vue.js 应用程序上存储我的私有 api 密钥?

Jae*_*ung 5 environment-variables vue.js vue-cli dotenv

我阅读了 Vue CLI 上的文档,我想确定我是否理解正确。

文档说,

Note that only NODE_ENV, BASE_URL, and variables that start with VUE_APP_ will be statically embedded into the client bundle with webpack.DefinePlugin. It is to avoid accidentally exposing a private key on the machine that could have the same name.

那么这是否意味着我应该在没有前缀 VUE_APP 的情况下存储我的私钥?例如,

VUE_APP_NOT_SECRET_KEY=not_secret_key
SECRET_KEY=secret_key
Run Code Online (Sandbox Code Playgroud)

存储我的密钥的方法是否正确?

alb*_*anx 13

您可以将密钥存储在 或 中 VUE_APP_NOT_SECRET_KEY=not_secret_keySECRET_KEY=secret_key从安全角度来看没有区别,任何具有最低前端技能的人都可以从浏览器读取此值。

\n

唯一的区别是,如果您使用VUE_APP_*前缀,您的变量将位于 process.env 中,并将在编译时使用 DefinePluing 被 Vue 替换。

\n

cli.vuejs.org/guide/mode-and-env.html#environment-variables \xe2\x80\x93

\n

请注意:您在 Vue 应用程序中存储的任何内容都不是秘密。

\n