使用$wire.$upload上传文件时Livewire默认上传事件不触发问题
问题:
$wire.$upload()上传文件时Livewire默认上传事件未触发 使用$wire.$upload(...args)上传文件时,Livewire的默认上传事件(如livewire-upload-start)无法触发,但通过wire:model方式上传时该功能完全正常。
Livewire源码中的$upload方法
以下是vendor/livewire/livewire/dist/livewire.js里的$upload方法代码:
// A JS API to upload a file directly to component // rather than through `wire:model`... $upload( name, // The property name file, // The File JavaScript object finish = () => { ... }, // Runs when the upload is finished... error = () => { ... }, // Runs if an error is triggered mid-upload... progress = (event) => { // Runs as the upload progresses... event.detail.progress // An integer from 1-100... }, )
我的AlpineJS事件监听代码
我通过AlpineJS监听上传事件的代码如下:
<div x-on:livewire-upload-start="console.log('upload started')"></div>
内容的提问来源于stack exchange,提问作者Dasun Tharanga
相关产品推荐
相关产品推荐

