Using Environment Variables with Vue.js

后端 未结 9 1412
礼貌的吻别
礼貌的吻别 2020-11-29 18:22

I\'ve been reading the official docs and I\'m unable to find anything on environment variables. Apparently there are some community projects that support environment variabl

9条回答
  •  情书的邮戳
    2020-11-29 18:46

    If you are using Vue cli 3, only variables that start with VUE_APP_ will be loaded.

    In the root create a .env file with:

    VUE_APP_ENV_VARIABLE=value
    

    And, if it's running, you need to restart serve so that the new env vars can be loaded.

    With this, you will be able to use process.env.VUE_APP_ENV_VARIABLE in your project (.js and .vue files).

    Update

    According to @ali6p, with Vue Cli 3, isn't necessary to install dotenv dependency.

提交回复
热议问题