element-ui upload组件 on-remove事件 传自定义参数

1.html

<el-form-item label="附件上传" prop="" >
    <!--:file-list="item.fileList"-->
    <el-upload
        class=""
        action="#"
        list-type="picture-card"
        :on-preview="handlePictureCardPreview"
        :before-upload="beforeLogoUpload"
        :http-request="uploadFile"
        :on-remove="(file, fileList) => {handleRemove(file, fileList, index)}"
    >
        <el-button size="small" type="primary" style="margin-left:-35px;" @click="markIndex(index)">点击上传</el-button>
    </el-upload>

2.script

handleRemove(file, fileList,fileIndex){}
Element UIUpload 组件主要用于文件上,但默认支持的是图片文件。如果你想在照片墙上显示非图片文件,比如文档、音频或视频等,并显示自定义图标,可以采取以下步骤: 1. **配置 Upload 组件**: 使用 `file-list-type` 属性指定文件列表显示的类型,例如设置为 'text' 或 'other',表示不是图片。 ```html <el-upload :action="uploadUrl" list-type="text" <!-- or 'other', depending on your needs --> :auto-upload="false" <!-- 阻止自动上,以便处理异步操作 --> > <el-button slot="trigger">点击选择文件</el-button> <el-icon v-if="previewVisible" class="file-preview-icon"></el-icon> <el-progress :percentage="progressPercent" v-if="showProgress"></el-progress> </el-upload> ``` 2. **处理文件预览和自定义图标**: - `on-change` 或 `on-success` 事件触发时,获取到文件信息,判断文件类型并设置自定义图标。你可以创建一个包含各种文件类型的映射,存储对应的图标路径。 ```javascript data() { return { fileIconMap: { doc: 'doc-icon.png', audio: 'audio-icon.png', video: 'video-icon.png', }, }; }, methods: { handleFileChange(file) { if (this.fileIconMap[file.type]) { this.previewVisible = true; this.filePreviewIcon = this.fileIconMap[file.type]; } }, } ``` 3. **图片墙展示**: 当用户点击上的文件时,可以根据文件类型动态生成 HTML 标签显示文件名和图标。例如: ```html <div v-for="(item, index) in files" :key="index"> <img :src="item.url || item.icon" alt="{{ item.name }}" /> <span>{{ item.name }}</span> <i class="el-icon-delete" @click="removeFile(index)"></i> </div> ``` 在这个例子中,`item.url` 是文件的真实URL(如果服务器返回了),如果没有,就使用 `item.icon` 来显示自定义图标。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值