【发布时间】:2020-06-21 15:39:22
【问题描述】:
我可以将数据传递给组件,但在 Alpine js 模式下,数据为空。
这是类:
public $code, $products;
public function getData($id)
{
$product = Product::find($id);
$this->code = $product->code;
}
public function render()
{
$this->products = Product::latest()->get();
return view('livewire.cabin');
}
这是组件:
<div x-data="{open: false}">
<section>
if I use $code here the code value is shown !!!
<div>{{ $code }}</div>
<div class="slideCabin">
@foreach($products as $product)
<div>
<img
@click="open = true"
wire:click="getData({{ $product->id }})"
src="/images/allproducts/{{ $product->cover }}"
>
</div>
@endforeach
</div>
</section>
这是由 Alpine js 通过点击标签打开的模态:
<div id="backmodal" x-show="open">
but, the code value is null:
<p>{{ $code }}</p>
</div>
【问题讨论】:
-
请展示您的完整组件和刀片。它对我来说不够清楚。我现在正在使用 livewire 一段时间。希望能帮到你
-
我将发布另一个涵盖我的问题的主题。请考虑一下。
-
确定兄弟....