Laravel Livewire PowerGrid报错:Button::confirm方法不存在
问题根源
你遇到的Method PowerComponents\LivewirePowerGrid\Button::confirm does not exist报错,是因为当前使用的PowerGrid版本(大概率是v4及以上)已移除Button类的confirm()方法,确认弹窗功能改用Livewire原生的wire:confirm指令实现。
解决方案
修改删除按钮代码,通过->attributes()方法添加wire:confirm属性实现确认弹窗,同时移除无需的target('_self')(emit操作无需跳转页面):
public function actions(): array { return [ Button::add('view') ->caption('Edit') ->class('btn btn-primary') ->route('productedit', ['id' => 'id']), Button::make('delete', 'Delete') ->class('btn btn-danger') // 添加强制确认的Livewire指令 ->attributes(['wire:confirm' => 'Are you sure you want to delete this record?']) ->emit('productdelete', ['id' => 'id']) ]; }
旧版本兼容说明
若使用PowerGrid v3及更早版本,需调用->confirmDialog()方法实现确认弹窗,示例如下:
Button::make('delete', 'Delete') ->class('btn btn-danger') ->confirmDialog([ 'title' => '确认删除', 'description' => 'Are you sure you want to delete this record?', 'confirmLabel' => '删除', 'cancelLabel' => '取消', ]) ->emit('productdelete', ['id' => 'id'])
内容的提问来源于stack exchange,提问作者Kesavaraj S
相关产品推荐
相关产品推荐

