Nuxt 3 wird in SSR nicht gerendert
P粉193307465
P粉193307465 2024-04-05 15:04:40
0
1
3645

Ich habe also ein Problem: Ich versuche, meine privaten Umgebungsvariablen abzurufen. Ich weiß, dass ich sie nur bekommen kann, wenn meine Seite SSR ist. Das Problem ist, dass ich es nie deaktiviert habe. Ich habe es auf meiner Seite dokumentiert console.log(process.server),它总是返回false. Ich finde das seltsam, da ich SSR nie deaktiviert habe.

Das ist meine 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'
            }
        ]
    }
})
P粉193307465
P粉193307465

Antworte allen(1)
P粉684720851

在您的浏览器中(也称为“客户端”),console.log(process.server)将始终记录false。 请查看您终端中的服务器控制台。在那里,除非您在“仅客户端”组件/插件中或在像onMounted这样的生命周期钩子中进行日志记录,否则它也应该被记录为true

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!