所以,我目前在我的一个项目中使用Laravel Livewire。但是,当我尝试通过 magic mathod 从一个组件向另一个组件发出事件时$refresh,它刷新了(在 xhr 请求中获得了 dom)整个组件,但前端没有实时更新。
ProductReviewForm.php 成分:
public function save()
{
//some functionalities ....
$this->emit('reviewSectionRefresh');
}
Run Code Online (Sandbox Code Playgroud)
ProductReviewSection.php 成分:
protected $listeners = [
'reviewSectionRefresh' => '$refresh',
];
public function render()
{
$this->review_lists = ProductReview::orderBy('id', 'DESC')->get();
return view('livewire.desktop.product-review-section');
}
Run Code Online (Sandbox Code Playgroud)
所以我想reviewSectionRefresh在我save()从第一个组件调用函数时发出要发出的事件,这应该被$listeners其他组件监听。这工作正常。同样在 xhr 中,我得到了刷新的 dom,但前端的组件没有更新。希望任何与 Livewire 合作的人都可以对此有所帮助。
我有两个组件 Posts 和 Post,Posts 显示帖子,通过单击图像,我想在另一个组件中显示单击的帖子的数据。
在下面发布类和组件:
组件视图:
<div class="post" x-data="{open:false}">
@foreach($posts as $post)
<div>
<h1>{{ $post->name }}</h1>
<h3>{{ $post->body }}</h3>
<img @click="open = !open" wire:click="showPost({{ $post->id }})" src="{{ $post->image }}" alt="">
</div>
@endforeach
<livewireL:post>
</div>
Run Code Online (Sandbox Code Playgroud)
组件类:
class Posts extends Component
{
public $posts, $post;
public function mount(){
$this->posts = Post::all();
}
public function showPost($id){
$post = Post::find($id);
$this->post = $post;
}
public function render()
{
return view('livewire.posts');
}
}
Run Code Online (Sandbox Code Playgroud)
这是我想在这个组件中显示点击数据的Post 组件和类,我已经尝试过 $emit 和许多文档,但没有结果。
我要呈现该数据的组件视图:
<div x-show="open">
<h1>{{ $post->name …Run Code Online (Sandbox Code Playgroud) 是否可以在不使用任何 js 代码的情况下将焦点从 laravel livewire 设置到另一个字段。
input wire:model="sku" wire:keydown.enter="getProductInfo" type="text">
Run Code Online (Sandbox Code Playgroud)
我试图在用户输入 sku 并按 Enter 时获取产品信息。如果找到详细信息,焦点必须转到最后一个字段。那么,是否可以在不使用任何外部 JavaScript 的情况下实现呢?