如何在 Vue.js 应用程序上存储我的私有 api 密钥?
·
问题:如何在 Vue.js 应用程序上存储我的私有 api 密钥?
我阅读了有关 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
存储我的密钥的正确方法是什么?
解答
您可以将密钥存储在VUE_APP_NOT_SECRET_KEY=not_secret_key或SECRET_KEY=secret_key中,从安全角度来看没有区别,任何具有最低前端技能的人都可以从浏览器中读取此值。
唯一的区别是,如果您使用VUE_APP_*前缀,您的变量将位于 process.env 中,并且将在编译时使用 DefinePluing 替换为 Vue。
cli.vuejs.org/guide/mode-and-env.html#environment-variables –
注意:您存储在 Vue 应用程序中的任何内容都不是秘密。
更多推荐

所有评论(0)