Using Environment Variables with Vue.js

后端 未结 9 1390
礼貌的吻别
礼貌的吻别 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:27

    1. Create two files in root folder (near by package.json) .env and .env.production
    2. Add variables to theese files with prefix VUE_APP_ eg: VUE_APP_WHATEVERYOUWANT
    3. serve uses .env and build uses .env.production
    4. In your components (vue or js), use process.env.VUE_APP_WHATEVERYOUWANT to call value
    5. Don't forget to restart serve if it is currently running
    6. Clear browser cache

    Be sure you are using vue-cli version 3 or above

    For more information: https://cli.vuejs.org/guide/mode-and-env.html

提交回复
热议问题