ant design 预览图片_ant-design-vue 上传图片组件

listType="picture-card"

class="avatar-uploader"

:showUploadList="false"

action="自己的api"

headers="{token:‘token值‘}"

:beforeUpload="beforeUpload"

@change="handleFrontImgChange">

placement="top">

:src="idCardFront"

alt="正面" />

type="loading" />

style="width:100%"

:src="idCardFront"

alt="正面" />

上传

handleFrontImgChange (info) {

if (info.file.status === ‘uploading‘) {

this.loadingFront = true;

return;

}

let res = info.file.response // 后端返回的数据

if (info.file.status === ‘done‘) {

this.loadingFront = false;

if (res.status && res.status != ‘1‘) {

this.$message.error(res.info)

return

}

this.idCardFront = res.data.fileName

}

if (info.file.status === ‘error‘) {

this.$message.error(res.error)

}

},

beforeUpload (file) {

const isJPG = file.type === ‘image/jpeg‘ || file.type === ‘image/png‘;

if (!isJPG) {

this.$message.error(‘仅支持jpeg/png格式!‘);

}

const isLt2M = file.size / 1024 / 1024 < 5;

if (!isLt2M) {

this.$message.error(‘上传不能超过5MB!‘);

}

return isJPG && isLt2M;

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,你的问题是如何在 Ant Design 的 Table 中显示预览图片。对吧? 如果是这样的话,可以考虑使用 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、付费专栏及课程。

余额充值