laravel - 命令线:jQuery中的poll.1000ms
问题描述
如何在livewire
使用 jQuery 代码时执行命令 <code>wire: poll.10000ms。我使用 jQuery 在视图内部检查输入值不为空,然后必须执行此命令。可能吗?
if (! $('#unitValue').val().length === 0) {
//Run wire:poll.10000ms="reUnit" with Jquery code
}
解决方案
您可能会做一些wire:poll.10000ms="reUnit"
事情来setInterval
将.event
Livewire
Component
活线组件
protected $listeners = [
'reUnit'
];
public function reUnit()
{
// do something here
}
刀片文件
<script>
document.addEventListener('DOMContentLoaded', function (e) {
setInterval(() => Livewire.emit('reUnit'), 10000);
})
</script>
我们在这里所做的只是创建一个ticks
每 10 秒一次的计时器,然后触发我们提供的函数,在本例中是一个Livewire
事件。
推荐阅读
- python - Python make a function always use a thread without calling thread.start()
- javascript - Building velo query function to sum total values from multiple datasets
- javascript - 我如何交换两个 bootstrap-vue 多个选择框的选定选项?
- javascript - why search not working after replace a letter in react-select
- c# - C# PropertyGrid UITypeEditor Agnostic to the object and property
- linux - mmap speed compared to read and write
- python - Using APIs to extract data from SaaS application Alloy
- asp.net-core - How to access HttpContext.Session from NextJs
- ubuntu - Problem with running Intellij 2021 sudo command
- javascript - How to get value from an object in AngularJS?