无法访问组件nuxt中的process.env变量
问题描述:
在nuxt配置中,我有env对象
In nuxt config I have env object
env: {
hey: process.env.hey || 'hey'
},
我想立即在组件模板中显示它:
as soon as I want to display it in component template:
{{ process.env.hey }}
我遇到错误
无法读取未定义的属性'env'
Cannot read property 'env' of undefined
任何想法会导致这种情况吗?
Any idea what can cause that?
答
进程
不能直接用于模板,但是您可以通过创建计算属性或将其添加到组件的状态来访问它。下面是一个示例:
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:
<template>
<div>{{ message }}</div>
</template>
export default {
computed: {
message() {
return process.env.hey;
},
},
};