最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - wire:click call two methods at once - Stack Overflow

programmeradmin1浏览0评论

I have a problem with wire:click event and I want to know, how to call two methods on one click. I have been tried several times without success, and I didn't found any information in the documentation so my examples:

in this case return method setItem is not defined, but the method is defined in the Livewire Component

wire:click="$emitTo('assign-modal', 'show-assign-modal'); setItem({{$book->id}})"

second case: in this case it's normal for me to not work, but I decided to give a chance and try what will happen

wire:click="$emitTo('assign-modal', 'show-assign-modal')" wire:click="setItem({{$book->id}})"

third case: in this case I have been tried to call the method with custom event, but still without success

wire:click="$emitTo('assign-modal', 'show-assign-modal'); $emitSelf('setData', {{$book->id}})"

Also I have an another idea, to pass the data to the first custom event assing-modal and after that to return the data to the parent ponent, but I think this idea is awful, so any help will be appreacited.

I have a problem with wire:click event and I want to know, how to call two methods on one click. I have been tried several times without success, and I didn't found any information in the documentation so my examples:

in this case return method setItem is not defined, but the method is defined in the Livewire Component

wire:click="$emitTo('assign-modal', 'show-assign-modal'); setItem({{$book->id}})"

second case: in this case it's normal for me to not work, but I decided to give a chance and try what will happen

wire:click="$emitTo('assign-modal', 'show-assign-modal')" wire:click="setItem({{$book->id}})"

third case: in this case I have been tried to call the method with custom event, but still without success

wire:click="$emitTo('assign-modal', 'show-assign-modal'); $emitSelf('setData', {{$book->id}})"

Also I have an another idea, to pass the data to the first custom event assing-modal and after that to return the data to the parent ponent, but I think this idea is awful, so any help will be appreacited.

Share Improve this question asked Nov 17, 2020 at 9:28 Plamen PenchevPlamen Penchev 4371 gold badge6 silver badges20 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

you cannot call 2 function in wire:click

so in this case you should do like this

wire:click="setItem({{$book->id}})"

in ponent

public function setItem($bookId)
{
    $emitTo('assign-modal', 'show-assign-modal'); 
}

Workaround: put a span enclosing the button with a wire:clik action, like this:

<span wire:click="printAll()">
    <button class="btn btn-primary" wire:click="$emit('showLoader')">
        Print All 
发布评论

评论列表(0)

  1. 暂无评论