【Avue upload上传组件回显文件名,并下载或打开图片】

文章讲述了如何使用Avueupload上传组件在uploadAfter方法中添加文件名后缀,并在uploadPreview方法中处理文件预览,以实现下载或打开图片的功能。同时,代码示例展示了如何在上传过程中处理文件大小限制和删除操作。
该文章已生成可运行项目,

Avue upload上传组件回显文件名,并下载或打开图片


重点就是在uploadAfter方法中添加文件名后缀,和uploadPreview方法中去掉后缀

          // 新增附件上传
          tempfileList:[],
          {
            label: "",
            prop: "",
            span: 24,
            arrow: false,
            collapse: true,
            display: true,
            column: [
              {
                label: "附件",
                prop: "attachment",
                span: 24,
                type: "upload",
                labelWidth: 80,
                display: true,
                loadText: "附件上传中,请稍等",
                dataType: "string",
                multiple: true,
                showFileList: true,
                tip: "文件大小不超过20Mb",
                props: {
                  value: "url", //看文档有解释
                  label: "url", //看文档有解释
                },
                propsHttp: {
                  res: "data",
                  url: "filePath",
                  name: "fileName",
                  home: upload.home,
                },
                action: upload.action,
                data: {
                  fileType: 1,
                },
                uploadPreview: (file, column, done) => {
                   //重点***
                  const lastIndex = file.url.lastIndexOf("/");
                  const url = file.url.slice(0, lastIndex);
                  window.open(url, "_blank");
                  return;
                },
                uploadBefore: (file, done, loading) => {
                  this.currentFileName = file.name;
                  let newFile = new File([file], file.name, {
                    type: file.type,
                  });
                  if (newFile.size > 20971520) {
                    this.$message.warning("文件大小不超过20Mb");
                    loading();
                    return;
                  }
                  done(newFile);
                },
                uploadAfter: (file, done) => {
                  this.tempfileList.push({ attachment: file.filePath });
                  //重点***
                  file.filePath = file.filePath + "/" + file.fileName;
                  done();
                },
                uploadDelete: (file) => {
                  this.tempfileList.splice(Number(file.uid), 1);
                },
              },
            ],
          },

如果小伙伴有更好的解决办法,欢迎补充~

本文章已经生成可运行项目
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值