laravel-livewire - Laravel Livewire:开放模式
问题描述
我有一张带有标记的地图。如果您单击此标记,它将运行它后面的 php。模态和标记是同一个组件。如何单击打开此组件?我已经尝试过 x-on 和 dispatchBrowserEvent。
我有一个适用于按钮的方法,但不适用于这个(wire:click =“”)。
零件:
<script>
var hqicon = L.icon({
iconUrl: '{{ asset('assets/map-icons/hq-icon.png') }}',
iconSize: [30, 30]
});
var maker = L.marker([{{ Auth::user()->company->hq->lat() }}, {{ Auth::user()->company->hq->lon() }}],{icon: hqicon}).addTo(map)
.on('click', function (e) {
window.livewire.emit('launchHqModal')
});
</script>
<x-jet-dialog-modal wire:model="HqModal" id="HqModal">
<x-slot name="title">
{{ __('Hoofdkantoor') }}
</x-slot>
<x-slot name="content">
</x-slot>
<x-slot name="footer">
</x-slot>
</x-jet-dialog-modal>
组件 php:
<?php
namespace App\Http\Livewire\Map;
use Livewire\Component;
class HqMarker extends Component
{
public $launchHqModal = false;
protected $listeners = ['launchHqModal'];
public function launchHqModal()
{
$this->dispatchBrowserEvent('launch-hq-modal');
$this->emit('launch-hq-modal');
$this->launchHqModal = true;
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\View\View|string
*/
public function render()
{
return view('map.hq-marker');
}
}
提前致谢
解决方案
推荐阅读
- ios - 通用链接在 testflight iOS (Expo) 上不起作用
- javascript - 如何从有多个孩子的父母那里访问特定的孩子状态?
- python - 如何将脚本路径作为数据块笔记本中的变量传递给 %run magic 命令?
- javascript - 使用 setInterval 反应倒计时计时器
- html - 如何在正文中的表格单元格之间添加空格而不影响标题
- python - 如何将每轮的pytorch模型输出存储到numpy
- python - 如何在一行中打印最终结果?
- javascript - 如何优化谷歌电子表格函数的执行时间?
- postgresql - 如何在 PostgreSQL 中查询 M2A 关系
- nginx - 无法在 Localhost 中为 Kibana 设置 Nginx 反向代理