[英]process.env not available under SPA mode in Nuxt.js
I put ENV params in an individual env.json and require it in nuxt.config.js, then extract the content into the env property of nuxt.config.js.我将 ENV 参数放在一个单独的 env.json 中并在 nuxt.config.js 中 require 它,然后将内容提取到 nuxt.config.js 的 env 属性中。
Under Universal and Static mode, it works good.在通用和静态模式下,它运行良好。 But under SPA mode, it bumps a TypeError with message:
但是在SPA模式下,它会抛出一个 TypeError 消息:
Cannot read property 'name' of undefined
无法读取未定义的属性“名称”
env.json:环境.json:
{
"site": {
"name": "Site Name",
"slogan": "Some Cool Line",
"description": "..."
}
}
nuxt.config.js: nuxt.config.js:
const env = require('./env')
export default {
mode: 'spa',
env: {
...env
},
head: {
titleTemplate: (page_title) => {
return page_title
? page_title + ' | ' + process.env.site.name
: process.env.site.name + ' - ' + process.env.site.slogan
},
...
Any sparks on how this problem can be solved?关于如何解决这个问题的任何火花?
I was trying to do the similar thing and this is what I did我试图做类似的事情,这就是我所做的
env: {
...env
},
// Global page headers (https://go.nuxtjs.dev/config-head)
head: {
// titleTemplate: '%s - nuxt-https',
titleTemplate: (page_title) => {
return this
? page_title + ' | ' + this.default.env.site.name // process.env.site.name
: process.env.site.name + ' - ' + process.env.site.slogan
},
title: 'Initial Title',
...
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.