Vxe UI vue vxe-table 如何在表格中使用上传附件、上传图片

Vxe UI vue vxe-table 如何在表格中使用上传附件、上传图片

效果图

在表格中显示缩略图模式上传附件或图片在这里插入图片描述在这里插入图片描述
点击更多按钮查看全部
在这里插入图片描述
鼠标拖动上传
在这里插入图片描述

代码

<template>
  <div>
    <vxe-grid v-bind="gridOptions"></vxe-grid>
  </div>
</template>

<script setup>
import { reactive } from 'vue'
const fileList1CellRender = reactive({
  name: 'VxeUpload',
  props: {
    readonly: true,
    moreConfig: {
      maxCount: 1,
      layout: 'horizontal'
    }
  }
})
const fileList2CellRender = reactive({
  name: 'VxeUpload',
  props: {
    multiple: true,
    showButtonText: false,
    moreConfig: {
      maxCount: 1,
      layout: 'horizontal'
    }
  }
})
const imgList1CellRender = reactive({
  name: 'VxeUpload',
  props: {
    mode: 'image',
    readonly: true,
    moreConfig: {
      maxCount: 1
    },
    imageStyle: {
      width: 40,
      height: 40
    }
  }
})
const imgList2CellRender = reactive({
  name: 'VxeUpload',
  props: {
    mode: 'image',
    multiple: true,
    showButtonText: false,
    moreConfig: {
      maxCount: 1
    },
    imageStyle: {
      width: 40,
      height: 40
    }
  }
})
const gridOptions = reactive({
  border: true,
  showOverflow: true,
  columns: [
    { type: 'seq', width: 70 },
    { field: 'name', title: 'Name', minWidth: 180 },
    { field: 'fileList1', title: '附件列表', width: 240, cellRender: fileList1CellRender },
    { field: 'fileList2', title: '上传附件', width: 300, cellRender: fileList2CellRender },
    { field: 'imgList1', title: '图片列表', width: 160, cellRender: imgList1CellRender },
    { field: 'imgList2', title: '上传图片', width: 210, cellRender: imgList2CellRender }
  ],
  data: [
    {
      id: 10001,
      name: 'Test1',
      imgList1: [],
      imgList2: [],
      fileList1: [
        { name: 'fj562.png', url: 'https://vxeui.com/resource/img/fj562.png' }
      ],
      fileList2: [
        { name: 'fj562.png', url: 'https://vxeui.com/resource/img/fj562.png' }
      ]
    },
    {
      id: 10002,
      name: 'Test2',
      imgList1: [
        { name: 'fj562.png', url: 'https://vxeui.com/resource/img/fj562.png' },
        { name: 'fj573.jpeg', url: 'https://vxeui.com/resource/img/fj573.jpeg' }
      ],
      imgList2: [
        { name: 'fj562.png', url: 'https://vxeui.com/resource/img/fj562.png' },
        { name: 'fj573.jpeg', url: 'https://vxeui.com/resource/img/fj573.jpeg' }
      ],
      fileList1: [],
      fileList2: []
    },
    {
      id: 10003,
      name: 'Test3',
      imgList1: [
        { name: 'fj577.jpg', url: 'https://vxeui.com/resource/img/fj577.jpg' }
      ],
      imgList2: [
        { name: 'fj577.jpg', url: 'https://vxeui.com/resource/img/fj577.jpg' }
      ],
      fileList1: [
        { name: 'fj562.png', url: 'https://vxeui.com/resource/img/fj562.png' },
        { name: 'fj573.jpeg', url: 'https://vxeui.com/resource/img/fj573.jpeg' },
        { name: 'fj187.jpg', url: 'https://vxeui.com/resource/img/fj187.jpg' }
      ],
      fileList2: [
        { name: 'fj562.png', url: 'https://vxeui.com/resource/img/fj562.png' },
        { name: 'fj573.jpeg', url: 'https://vxeui.com/resource/img/fj573.jpeg' },
        { name: 'fj187.jpg', url: 'https://vxeui.com/resource/img/fj187.jpg' }
      ]
    }
  ]
})
</script>
在 `vxetable` ,实现表格列宽可以自定义拖拽的方式,可以通过配置 `column-resizing` 属性来实现。 具体来说,你需要在 `columns` 属性为每一列设置 `resizable: true`,以指示该列可以进行列宽调整。然后,在 `tableProps` 属性,你可以将 `column-resizing` 属性设置为一个对象,该对象包含一个 `handleWidth` 属性(可选),以指定列调整的手柄宽度,和一个 `minWidth` 属性(可选),以指定列的最小宽度。 例如,下面是一个实现了自定义拖拽表格列宽的 `vxetable` 示例代码: ```vue <template> <vxe-table :data="tableData" :columns="tableColumns" :table-props="tableProps" /> </template> <script> export default { data() { return { tableData: [ { name: 'John', age: 22, gender: 'Male' }, { name: 'Jane', age: 30, gender: 'Female' }, { name: 'Bob', age: 45, gender: 'Male' } ], tableColumns: [ { field: 'name', title: 'Name', resizable: true }, { field: 'age', title: 'Age', resizable: true }, { field: 'gender', title: 'Gender', resizable: true } ], tableProps: { columnResizing: { handleWidth: 5, minWidth: 50 } } } } } </script> ``` 在上面的代码,`tableData` 和 `tableColumns` 分别是表格的数据和列定义,其每一列都设置了 `resizable: true`,以允许列宽调整。在 `tableProps` ,我们将 `column-resizing` 设置为一个对象,其 `handleWidth` 属性设置为 `5`,以指定列调整的手柄宽度为 `5px`,并将 `minWidth` 属性设置为 `50`,以指定列的最小宽度为 `50px`。 这样,在 `vxetable` ,你就可以通过简单的配置实现表格列宽可以自定义拖拽了。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值