【发布时间】:2021-10-22 11:20:58
【问题描述】:
我正在使用带有 Laravel 8.x 的 Blade,并希望在 Alpine JS (v3) 中使用 x-show 显示或隐藏表格行。
<table>
@foreach($items as $item)
<div x-data="{show: false}">
<tr>
<td>
<button type="button" x-on:click="show = !show">
Toggle Show
</button>
</td>
</tr>
<tr x-show="show">
<td>{{ $item->name }}</td>
</tr>
</div>
@endforeach
</table>
然而,当我这样做时,我得到一个ReferenceError: show is not defined 错误。这种方法是否可能不使用x-for,因为我仍然希望能够访问行中的 Blade 变量。
【问题讨论】:
标签: javascript laravel laravel-blade alpine.js