所以我遇到了一个问题,我正在尝试获取我的私有环境变量。我知道只有在我的页面是ssr时才能获取它们。问题是我从来没有禁用过它。我在我的页面中记录了console.log(process.server),它总是返回false。我觉得这很奇怪,因为我从来没有禁用过ssr。
这是我的nuxt.config.ts:
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
ssr: true,
routeRules: {
'/portal/**': { ssr: false },
'/checkout/**': { ssr: false }
},
runtimeConfig: {
stripeKey: '',
public: {
API_BASE_URL: process.env.API_BASE_URL || "http://192.168.1.100:8000/api",
}
},
modules: [
'@nuxtjs/i18n',
'@pinia/nuxt',
],
css: [
'@/assets/css/main.css',
'@/assets/css/colors.scss',
'vuetify/lib/styles/main.sass',
'primevue/resources/themes/lara-light-blue/theme.css',
'primevue/resources/primevue.css',
'primeicons/primeicons.css',
'@fortawesome/fontawesome-svg-core/styles.css'
],
build: {
transpile: [
'primevue',
'vuetify'
]
},
postcss: {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
},
app: {
head: {
script: [{ src: "https://js.stripe.com/v3/" }],
title: '',
meta: [
{
name: 'color-scheme',
content: 'only light'
}
],
link: [
{
href: 'https://fonts.googleapis.com/css?family=Material+Icons|Material+Icons+Outlined',
rel: 'stylesheet',
}
]
}
},
i18n: {
lazy: true,
langDir: "locales",
strategy: "no_prefix",
locales: [
{
code: 'en',
iso: 'en',
name: 'English',
file: 'en.json'
},
{
code: 'nl-Nl',
iso: 'nl-NL',
name: 'Dutch',
file: 'nl-NL.json'
}
]
}
}) Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
在您的浏览器中(也称为“客户端”),
console.log(process.server)将始终记录false。 请查看您终端中的服务器控制台。在那里,除非您在“仅客户端”组件/插件中或在像onMounted这样的生命周期钩子中进行日志记录,否则它也应该被记录为true