Can not access process.env variables in component nuxt

前端 未结 3 888
广开言路
广开言路 2021-01-18 01:09

In nuxt config I have env object

env: {
    hey: process.env.hey || \'hey\'
},

as soon as I want to display it in component template:

3条回答
  •  死守一世寂寞
    2021-01-18 01:39

    process isn't directly available to templates, but you can access it by creating a computed property or adding it to your component's state. Here's an example:

    
    
    export default {
      computed: {
        message() {
          return process.env.hey;
        },
      },
    };
    

提交回复
热议问题