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
    评论
好的,你的问题是如何在 Ant DesignTable 中显示预览图片。对吧? 如果是这样的话,可以考虑使用 Ant Design 中的 Upload 组件和 Modal 组件来实现。具体步骤如下: 1. 在 Table 中,使用 render 函数来渲染每一行的数据,其中包括需要显示预览图片的列。 2. 在 render 函数中,使用 Upload 组件来上传图片,并将图片的 url 存储在 state 中。 3. 在 render 函数中,使用 Modal 组件来显示预览图片。当用户点击图片时,Modal 组件会显示图片的预览。 下面是一个简单的示例代码: ```javascript <template> <a-table :columns="columns" :data-source="data"> <template #avatar="text"> <a-upload :show-upload-list="false" :before-upload="handleUpload" > <a-avatar :src="avatarUrl" /> </a-upload> <a-modal :visible="previewVisible" @cancel="handleCancel"> <a-img :src="previewImage" /> </a-modal> </template> </a-table> </template> <script> export default { data() { return { data: [ { name: "John Brown", age: 32, avatarUrl: "", }, ], previewVisible: false, previewImage: "", }; }, methods: { handleUpload(file) { // 上传图片,并将图片的 url 存储在 state 中 this.avatarUrl = URL.createObjectURL(file.raw); }, handlePreview(url) { // 显示图片预览 this.previewImage = url; this.previewVisible = true; }, handleCancel() { // 隐藏图片预览 this.previewVisible = false; }, }, computed: { columns() { return [ { title: "Name", dataIndex: "name", }, { title: "Age", dataIndex: "age", }, { title: "Avatar", dataIndex: "avatarUrl", scopedSlots: { customRender: "avatar" }, width: "20%", }, ]; }, }, }; </script> ``` 在这个示例中,我们使用了 Upload 组件来上传图片,并将图片的 url 存储在 state 中。在 render 函数中,我们使用了 Modal 组件来显示预览图片。当用户点击图片时,Modal 组件会显示图片的预览。 希望这可以帮助到你!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值