首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未触发Livewire emit

未触发Livewire emit
EN

Stack Overflow用户
提问于 2021-09-21 09:14:51
回答 1查看 155关注 0票数 0

我试图在点击编辑按钮时显示一个模式,所以我添加了wire:click

代码语言:javascript
复制
    <td class="py-3 px-6 text-left">
        <div class="flex items-center">
            <span class="font-medium">{{ $project->project }}</span>
        </div>
    </td>

    <td class="py-3 px-6 text-left">
        <div class="flex items-center">
            <span>{{ $project->username }}</span>
        </div>
    </td>
    
    <td class="py-3 px-6 text-center">
        <span class="bg-{{ $project->status_color }}-200 text-{{ $project->status_color }}-600 py-1 px-3 rounded-full text-xs"> {{ $project->status_name }} </span>
    </td>

    <td class="py-3 px-6 text-center">
        <div class="flex item-center justify-center">

        <button class="bg-indigo-500 hover:bg-indigo-700 text-white font-bold py-1 px-4 rounded" wire:click="edit">
          edit
        </button>

        </div>
    </td>
</tr>

下面是我的组件:

代码语言:javascript
复制
use Livewire\Component;

class Dashboard extends Component {
    use WithPagination;

    public function edit() {
        $this->emit('eModal');
    }
}

在按钮所在的livewire刀片中,我添加了按钮的模式和脚本:

代码语言:javascript
复制
<!-- Modal -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

@push('scripts')

<script>
   Livewire.on('eModal', () =>{
     console.log('scsa');
  $('#editModal').modal('show');
});
</script>

@endpush

我将console.log添加到脚本中,这样我就可以查看是否触发了emit,但是什么也没有发生,我在控制台上什么也没有得到。我尝试了dispatchBrowserEvent,但是同样的结果;什么也没有发生。

有人能帮我吗?谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-21 09:30:09

尝试在您的主刀片文件上添加一个livewire事件:

代码语言:javascript
复制
    <script>
    Livewire.on('eModal', () =>{
      console.log('scsa');
      $('#editModal').modal('show');
    });
   </script>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69266350

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档