antd 中 upload的下载图标

<template>
  <div>
    <a-upload
      action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
      :default-file-list="defaultFileList"
      @download="downHandle"
      :showUploadList="{
        showRemoveIcon: true,
        showDownloadIcon: true,
      }"
      @change="changeD"
    >
      <a-button> <a-icon type="upload" /> Upload </a-button>
    </a-upload>
    <input type="file" @change="handleChange" />
  </div>
</template>
<script>
export default {
  data() {
    return {
      defaultFileList: [
        {
          uid: "1",
          name: "xxx.png",
          status: "done",
          response: "Server Error 500", // custom error message to show
          url: "",
        },
        {
          uid: "2",
          name: "yyy.png",
          status: "done",
          url: "http://www.baidu.com/yyy.png",
        },
        {
          uid: "3",
          name: "zzz.png",
          status: "error",
          response: "Server Error 500", // custom error message to show
          url: "http://www.baidu.com/zzz.png",
        },
      ],
      downUrl: "",
    };
  },
  methods: {
    handleChange({ file, fileList }) {
      if (file.status !== "uploading") {
        console.log(file, fileList);
      }
    },
    changeD(file) {
      console.log("改变");
    },
    downHandle(file) {
      console.log(file, "点击文件");
    },
//将文件转化成base64用来测试
    handleChange(file) {
      //console.log(file, 49);
      let that = this;
      const _file = file.target.files[0];
      const reader = new FileReader();
      reader.onload = function (e) {
        that.downUrl = e.target.result;
        //console.log(that.downUrl, 58);
        that.defaultFileList[0].url = that.downUrl;
      };
      reader.readAsDataURL(_file);
    },
  },
 
};
</script>

 总结:之前一直点击都进不去download方法,现在加了以下显示图标后就可以了

1

 默认情况下直接点击文件后直接跳转到defaultFileList中点击的url,如果是执行了download方法就不默认走而是自己在里面写的逻辑了

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值