mar*_*aet 2 javascript laravel laravel-livewire
您能否告诉我是否可以获取 Javascript 字段的值并将其传递给 Laravel Livewire 属性:
首先,我使用 Javascript 在输入中加载以下值:
document.getElementById('lat-span').value = (place.geometry['location'].lat());
Run Code Online (Sandbox Code Playgroud)
这会加载带有值的输入,现在我尝试使用wire:model检索该值,它显示为空,我知道它没有按照我的想法完成:
<input wire:model="latitud" value="lat-span" id="lat-span" />
Run Code Online (Sandbox Code Playgroud)
如何直接将此 javascript 值传递给 Livewire 属性?
<script>
// ....
Livewire.emit('getLatitudeForInput', place.geometry['location'].lat());
</script>
Run Code Online (Sandbox Code Playgroud)
在组件中
public $latitud;
protected $listeners = [
'getLatitudeForInput'
];
//
public function getLatitudeForInput($value)
{
if(!is_null($value))
$this->latitud = $value;
}
Run Code Online (Sandbox Code Playgroud)
在巴尔德只是
<input wire:model="latitud" id="lat-span" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10704 次 |
| 最近记录: |