ant design vue table,upload相关问题

 1.后端传过来的数据不是自己想要,然后如何去格式化?

<template>
        <a-table
            :columns="columns"
            :data-source="data"
            size="middle"
            :row-key="record => record.id"
            :pagination="paginationOption"
            :loading="loading"
            @change="change"
          >
            <template slot="handle" slot-scope="text, record">
              <a href="javascript:;"  @click="see(record)">预览文件</a>
              <a href="javascript:;"  @click="del(record)">删除文件</a>
            </template>
          </a-table>
</template>


//格式化时间
function formatterTime(time){
  // 2020-07-17T17:02:52
  let t1 = time.slice(0,10)
  let t2 = time.slice(11)
  return t1 + ' ' + t2
}
//格式化文件大小
function formatterFileSize(size){
  // 1078729
  if(size / 1024 / 1024 > 1){
    return (size / 1024 / 1024).toFixed(2) + 'M'
  }else{
    if(size / 1024 > 1) {
      return (size / 1024).toFixed(2) + 'K'
    }else{
      return size.toFixed(2) + 'B'
    }
  }
}

const columns = [
  {
    title: "文件名称",
    dataIndex: "name"
    // key: 'name',
  },
  {
    title: "文件大小",
    dataIndex: "maxSize",
    // key: 'maxSize',
    customRender: (text, row, index) => {
      return formatterFileSize(text)
    }
  },
  {
    title: "上传日期",
    dataIndex: "updTime",
    // key: 'updTime',
    customRender: (text, row, index) => {
      return formatterTime(text)
    }
  },
  {
    title: "操作",
    dataIndex: "handle",
    // key: 'handle',
    align: "center",
    scopedSlots: { customRender: "handle" }
  }
];

 

2.upload上传文件出了一点问题

     <template>     
          <a-upload
            name="file"
            :showUploadList="false"
            :customRequest="customRequest"
            accept=".jpg, .jpeg, .png, .bmp, .tif, .gif, .PDF, .doc, .docx"
          >
            <div class="btn">
              <a-icon type="plus" />上传文件
            </div>
          </a-upload>
     </template>  

<script>
export default {
    data() {
        return {
            thisId: 0,
        }
    },
    methods: {
        //自定义上传文件
        customRequest(info) {
          const formData = new FormData();
          formData.append("bizId", this.thisId);
          formData.append("file", info.file);
          this.saveFile(formData,info);
        },
        //上传文件
        saveFile(formData,info) {
            //addAttachment 为上传的接口
          addAttachment(formData).then(res => {
            this.$message.success(`${info.file.name} 上传成功`);
          }).catch(err => {
            console.error(err);
            this.$message.error(`${info.file.name} 上传失败`);
          })
        },
    }
}
</script>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值