bramdeleeuw / silverstripe-inertia
SilverStripe 的 Inertia 服务器端适配器
dev-main
2021-06-05 19:40 UTC
Requires
- silverstripe/framework: >=4.0
This package is auto-updated.
Last update: 2024-09-06 03:01:16 UTC
README
此模块仍在开发中,欢迎提供帮助/PR!
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 传递的属性。