亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從 javascript 更新輸入字段時,Laravel livewire 模型不起作用?

從 javascript 更新輸入字段時,Laravel livewire 模型不起作用?

holdtom 2023-09-21 17:15:43
我有一個文本輸入字段,如果我在其中輸入時自己更新它,效果會很好,但是,我需要的是讓這個輸入字段填充來自 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" 輸入字段將填充新數據: 但它不會進行新的 fetch 調用來獲取數據,最后一個調用是在沒有 javascript 的情況下插入的“123”數據......知道如何在從 javascript 更新輸入值后獲取數據嗎?
查看完整描述

4 回答

?
慕桂英4014372

TA貢獻1871條經驗 獲得超13個贊

使用javascript更改輸入值后,可以觸發輸入事件以使livewire更新模型。

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

如果您使用wire:model.lazy,則應該使用“change”事件而不是“input”


查看完整回答
反對 回復 2023-09-21
?
瀟湘沐

TA貢獻1816條經驗 獲得超6個贊

<script>

        document.addEventListener('livewire:load', function () {

           @this.set('images','Hello');

           //console.log('Hello');

        });

</script>

創建一個公共屬性名稱“images”,在掛載中啟動它。我希望它能解決你的問題。讓我知道。


查看完整回答
反對 回復 2023-09-21
?
FFIVE

TA貢獻1797條經驗 獲得超6個贊

您可以使用 livewire 中的內聯腳本填充輸入字段,例如:


document.addEventListener('livewire:load',function ()

        {

            @this.images = "Hello";

        });

<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">


查看完整回答
反對 回復 2023-09-21
?
鳳凰求蠱

TA貢獻1825條經驗 獲得超4個贊

在輸入字段的父元素上添加wire:ignore


喜歡


<div wire:ignore>


   <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">


</div>


查看完整回答
反對 回復 2023-09-21
  • 4 回答
  • 0 關注
  • 244 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號