| 1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- namespace App\Livewire\Traits;
- trait WithMathRender
- {
- public function bootWithMathRender(): void
- {
- // 标记该组件需要数学公式渲染
- $this->dispatch = array_merge($this->dispatch ?? [], [
- 'math:render' => 'triggerMathRender'
- ]);
- }
- public function triggerMathRender(): void
- {
- // 这个方法可以被前端调用来手动触发数学公式渲染
- $this->dispatch('math-rendered');
- }
- protected function renderMathContent(string $content): string
- {
- // 在服务器端预解析数学公式(可选)
- // 注意:通常我们只在客户端渲染,这里只是预处理
- return $content;
- }
- /**
- * 在视图中调用以获取需要渲染的内容
- */
- public function getMathContent($content): string
- {
- return $this->renderMathContent($content ?? '');
- }
- }
|