无法访问组件nuxt中的process.env变量 [英] Can not access process.env variables in component nuxt
本文介绍了无法访问组件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;
},
},
};
这篇关于无法访问组件nuxt中的process.env变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文