Webman + Vue3 如何实现 SSG(服务端生成)?

fgt1t5y

问题描述

最近在做一个论坛系统,需要SEO性良好,可被爬虫、搜索引擎抓取,所以我准备用SSG技术配合Vue3去做,从网上查了很多资料,却没有Vue3配合PHP实现SSG的相关教程。

有大佬做过类似的需求吗?

SSG的详细描述:

截图

https://cn.vuejs.org/guide/extras/ways-of-using-vue.html#jamstack-ssg

384 3 0
3个回答

咸鱼不咸

用nuxt

nitron

有时候就觉得奇怪,明明很传统的技术,换了个名字,新瓶装的旧酒,就能让人不知所以

lunzi

laravel的那个inertia你研究一下试试,支持服务端渲染,不知道是不是你说的这个

import { createSSRApp, h } from 'vue';
import { renderToString } from '@vue/server-renderer';
import { createInertiaApp } from '@inertiajs/vue3';
import createServer from '@inertiajs/vue3/server';
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m';

const appName = import.meta.env.VITE_APP_NAME || 'Laravel';

createServer((page) =>
    createInertiaApp({
        page,
        render: renderToString,
        title: (title) => `${title} - ${appName}`,
        resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
        setup({ App, props, plugin }) {
            return createSSRApp({ render: () => h(App, props) })
                .use(plugin)
                .use(ZiggyVue, {
                    ...page.props.ziggy,
                    location: new URL(page.props.ziggy.location),
                });
        },
    })
);
🔝