vue iview upload组件上传文件,show-upload-list:true配合form,modal使用

<template>

<div class="contain_box">

<FormItem label="走访视频" prop="visitVideo">

<Upload

ref="video"

action="#"

multiple

show-upload-list

accept=".3gp,.mp4,.wmv,.avi"

:before-upload="beforeVisitVideo"

:on-remove="removeVideo"

>

<Button icon="ios-cloud-upload-outline" type="primary" ghost

>点击上传</Button

>

</Upload>

<div

style="display: flex; height: 80px; margin-top: 5px"

v-for="(item, index) in videoDefault"

:key="index"

>

<video

id="media"

class="media"

style="width: 84%"

controls

:src="item"

></video>

<span style="line-height: 86px">

<Tooltip content="删除" placement="right">

<Icon

class="iconDele"

type="ios-close-circle-outline"

size="30"

@click="videoDele(index)"

/>

</Tooltip>

</span>

</div>

<!-- <div

class="fileName"

v-for="(item, index) in visitVideo"

:key="index"

> -->

<!-- <span> {{ item.name }}</span> -->

<!-- 删除按钮,点击上传文件对象清空,可以重新上传 -->

<!-- @click=" -->

<!-- <Icon type="ios-close" size="20" color="#000" class="iconDele" /> -->

<!-- </div> -->

</FormItem>

<FormItem label="走访录音" prop="visitRecording">

<Upload

ref="sound"

action="#"

multiple

accept=".mp3,.wav,.m4a,.3pg,.mar,.wma"

:before-upload="beforeVisitSound"

:on-remove="removeSound"

>

<Button icon="ios-cloud-upload-outline" type="primary" ghost

>点击上传</Button

>

</Upload>

<div

style="display: flex; height: 54px; margin-top: 5px"

v-for="(item, index) in soundDefault"

:key="index"

>

<audio :src="item" controls="controls" ref="player" preload="true">

<!--(1)属性:controls,preload

(2)事件:canplay,timeupdate,ended

(3)方法:play(),pause() controls:向用户显示音频控件(播放/暂停/进度条/音量)

preload:属性规定是否在页面加载后载入音频

canplay:当音频/视频处于加载过程中时,会发生的事件

timeupdate:当目前的播放位置已更改时

ended:当目前的播放列表已结束时-->

</audio>

<span style="line-height: 63px">

<Tooltip content="删除" placement="right">

<Icon

class="iconDele"

type="ios-close-circle-outline"

size="30"

@click="soundDele(index)"

/>

</Tooltip>

</span>

</div>

</FormItem>

</div>

</template>

data(){

return {

// 走访视频

videoFile: [],

// 走访录音

soundFile: [],

// 回显视频

videoDefault: [],

// 回显录音

soundDefault: [],

}}

// 组件初始化完成后要给upload的fileList一个数组容器,否则,上传文件后,组件将无法在页面默认展示上传列表

mounted() {

//切记,一定要给组件数据容器

this.videoFile = this.$refs.video.fileList;

this.soundFile = this.$refs.sound.fileList;

},

// 弹框开关回调

modalChange(val) {

// console.log(val);

if (!val) {

// 弹框关闭时清空所有组件信息,否则再次点开弹框时,因为vue的双向绑定,会展示上次表单数据

this.$refs["executedForm"].resetFields();

this.videoFile = [];

this.soundFile = [];

// upload组件清空方法

this.$refs.sound.clearFiles();

this.$refs.video.clearFiles();

} else {

//这里特别容易被丢失,切记

// 由于弹框关闭时,上传upload的fileList被清空了,灵魂再次无法安放了,

// 只能再次给予body(容器)得以安放并静静依次排列展示

this.soundFile = this.$refs.sound.fileList;

this.videoFile = this.$refs.video.fileList;

}

},

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue使用 Upload 组件 Excel 文件并发送 http 请求的步骤如下: 1. 在 Vue 组件中引入 Upload 组件: ```vue <template> <el-upload class="upload-excel" action="/api/upload" :on-success="handleSuccess" :before-upload="beforeUpload" :file-list="fileList" :accept=".xlsx, .xls" :auto-upload="false" > <el-button slot="trigger" size="small" type="primary">上 Excel 文件</el-button> <div slot="tip" class="el-upload__tip">只能上 .xlsx 或 .xls 格式的文件</div> </el-upload> </template> ``` 2. 在 Vue 组件的 `methods` 中定义 `handleSuccess` 和 `beforeUpload` 方法: ```javascript methods: { handleSuccess(response, file, fileList) { // 上成功后的处理逻辑 }, beforeUpload(file) { // 上前的校验逻辑,如文件大小、文件类型等 } } ``` 3. 在 `handleSuccess` 方法中发送 http 请求: ```javascript methods: { handleSuccess(response, file, fileList) { // 发送 http 请求 axios.post('/api/uploadExcel', { file: file }).then(res => { // 处理 http 请求返回的数据 }).catch(err => { // 处理请求错误 }) }, beforeUpload(file) { // 上前的校验逻辑,如文件大小、文件类型等 } } ``` 4. 在后台编写对应的接口处理上的 Excel 文件。可以使用如下示例代码解析上的 Excel 文件: ```python import pandas as pd def handle_upload_excel(request): file = request.files['file'] df = pd.read_excel(file) # 处理解析后的数据 return jsonify({'code': 0, 'message': '上成功'}) ``` 需要注意的是,在后台接收到上文件后,需要对其进行处理并返回相应的结果。以上就是在 Vue使用 Upload 组件 Excel 文件并发送 http 请求的基本流程。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值