You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用$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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 05:02:04