从javascript更新输入字段时,Laravel livewire模型不工作?

从javascript更新输入字段时,Laravel livewire模型不工作?,javascript,laravel,laravel-livewire,Javascript,Laravel,Laravel Livewire,我有一个文本输入字段,如果我在里面键入时自己更新它,它会非常有用,但是,我需要的是用javascript而不是用户的数据填充这个输入字段。 这是我的输入字段 <input type="text" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"

我有一个文本输入字段,如果我在里面键入时自己更新它,它会非常有用,但是,我需要的是用javascript而不是用户的数据填充这个输入字段。 这是我的输入字段

<input type="text" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="images" wire:model="images">

如果我在输入字段中键入“123”,则会发生这种情况,输入字段的值为:

但是,当我使用javascript更新它时,
document.getElementById(“images”).value=“Hello”
输入字段将填充新数据:

但是它不会进行新的获取调用来获取数据,最后一个调用是使用“123”数据,该数据是在没有javascript的情况下插入的


您知道如何在从javascript更新输入值后获取数据吗?

您可以使用livewire中的内联脚本填充输入字段 比如:

document.addEventListener('livewire:load',function()
{
@this.images=“你好”;
});

您可以使用livewire中的内联脚本填充输入字段 比如:

document.addEventListener('livewire:load',function()
{
@this.images=“你好”;
});

使用javascript更改输入值后,您可以触发输入事件以使livewire更新模型

document.getElementById("images").value = 'Hello';
document.getElementById("images").dispatchEvent(new Event('input'));

如果您使用的是wire:model.lazy,则应使用“更改”事件而不是“输入”

在使用javascript更改输入值后,您可以触发输入事件以使livewire更新模型

document.getElementById("images").value = 'Hello';
document.getElementById("images").dispatchEvent(new Event('input'));
<script>
        document.addEventListener('livewire:load', function () {
           @this.set('images','Hello');
           //console.log('Hello');
        });
</script>
如果您使用的是wire:model.lazy,则应该使用“更改”事件而不是“输入”


<script>
        document.addEventListener('livewire:load', function () {
           @this.set('images','Hello');
           //console.log('Hello');
        });
</script>
document.addEventListener('livewire:load',function(){ @this.set('images','Hello'); //log('Hello'); });
创建一个公共属性名“映像”,并在挂载中启动它。我希望它能解决你的问题。让我知道。


document.addEventListener('livewire:load',function(){
@this.set('images','Hello');
//log('Hello');
});

创建一个公共属性名“映像”,并在挂载中启动它。我希望它能解决你的问题。让我知道。

我应该在哪里添加此事件侦听器?在您的livewire刀片文件中。。。仅供参考:它不起作用…有没有办法在不触发livewire更新的情况下进行更改?我应该在哪里添加此事件侦听器?在livewire刀片文件中。。。仅供参考:它不起作用……有没有办法在不触发livewire更新的情况下进行更改?