bramdeleeuw/silverstripe-inertia

SilverStripe 的 Inertia 服务器端适配器

安装: 6

依赖者: 0

建议者: 0

安全: 0

星标: 2

关注者: 2

分支: 1

公开问题: 0

类型:silverstripe-vendormodule

dev-main 2021-06-05 19:40 UTC

This package is auto-updated.

Last update: 2024-09-06 03:01:16 UTC


README

此模块仍在开发中,欢迎提供帮助/PR!

Inertia 允许您创建完全客户端渲染的单页应用程序,而无需处理现代单页应用程序的复杂性。它是通过利用现有的服务器端框架来实现的。

了解更多关于 Inertia 的信息

安装

通过 composer 安装模块

composer require bramdeleeuw/silverstripe-inertia

将 $Inertia 添加到您的 Page.ss 布局中。

$Inertia($pageJson)

这将渲染以下片段

<div id="app" data-page="{the page data}"></div>

在您的控制器中,您可以添加以下方法来填充您的 vue/react 等. 应用程序。

<?php

use SilverStripe\CMS\Controllers\ContentController;
use Inertia\Inertia;

class PageController extends ContentController
{
    public function index()
    {
        return Inertia::render('Page', [
            'title' => $this->Title,
            'content' => $this->Content
        ]);
    }
}

在初始请求中,这将使用传递的属性填充 data-page。Inertia 发出的后续请求将接收作为 json 传递的属性。

维护者

Bram de Leeuw