如何解决使用livewire更新变更?
我有qty
的此输入类型编号:
<span class="qty-btn minus-btn" onclick="this.parentNode.querySelector('input[type=number]').stepDown()">
<i class="fal fa-minus-circle"></i>
</span>
<input
wire:model.lazy="quantity"
wire:change="updateQuantity({{ $product->id }})"
type="number"
class="input-text qty text"
title="Qty" inputmode="numeric"
step="1" min="1" max="" lang="en"
>
<span class="qty-btn plus-btn" onclick="this.parentNode.querySelector('input[type=number]').stepUp()">
<i class="fal fa-plus-circle"></i>
</span>
当我单击任何按钮stepDown
或stepUp
时,我需要更新qty
我的Livewire竞争对手:
class CartQtySection extends Component
{
public $product;
public $quantity;
public function mount($product)
{
$this->product = $product;
$this->quantity = $product->pivot->quantity;
}
public function updateQuantity($id)
{
user()->cart()->updateExistingPivot($id,[
'quantity' => $this->quantity,]);
$this->emit('quantityUpdated');
}
}
解决方法
尝试wire:click
<span class="qty-btn minus-btn" wire:click="stepDown({{ $product->id }})">
<i class="fal fa-minus-circle"></i>
</span>
<span class="qty-btn plus-btn" wire:click="stepUp({{ $product->id }})">
<i class="fal fa-plus-circle"></i>
</span>
在组件中
<?php
class CartQtySection extends Component
{
public $product;
public $quantity;
public function mount($product)
{
$this->product = $product;
$this->quantity = $product->pivot->quantity;
}
public function updateQuantity($id)
{
user()->cart()->updateExistingPivot($id,[
'quantity' => $this->quantity,]);
$this->emit('quantityUpdated');
}
public function stepDown($id)
{
$this->quantity++;
$this->updateQuantity($id)
}
public function stepUp($id)
{
$this->quantity--;
$this->updateQuantity($id)
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。