【发布时间】:2022-01-16 06:27:27
【问题描述】:
刀片组件是否可以通过onclick调用函数,并更改其变量值?
public $rental = true;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.product-rental');
}
public function toggleRental(){
$this->rental = !$this->rental;
}
<div class="row">
<div class="col col-md-6">
<div class="form-check form-switch">
<input class="form-check-input" name="rental" type="checkbox" @click="toggleRental()" id="rental" value="1" checked>
<label class="form-check-label" for="rental">Rental</label>
</div>
</div>
</div>
{{$rental}}
基本上,我想要的是当我点击一个按钮时,它会从刀片组件调用“toggleRental()”函数并更新“$rental”变量。这可能吗?
【问题讨论】:
标签: laravel laravel-blade