react与antd搭配实现图片上传与设置主图功能

antd的upload可以实现上传,但是其上传之后,图片列表展示都是其组件里面已经封装好的,也没有vue那种提供插槽solt的功能,但是我司需要实现在每张图片下方有个radio标签来设置主图,左思右想,是不是得直接把upload组件拿过来再自己封装一层呢?实力不允许也没办法。

 so 我的解决办法是,封装一个组件,里面有upload组件,上传成功的话,将fileList filter出来,用图片展示,图片和radio可以封装的把,这并不难,直接放下代码把:

import React, { Component } from 'react';
import { Upload, message, Icon, Modal, Radio, Card } from 'antd';
import config from '../../../../config';
import { getCookie } from 'Utils/publicFunc';
import './UploadPhoto.scss';

class UploadPhoto extends Component {
    constructor(props) {
        super(props);
        this.state = {
            showModal: false,
            previewImage: '',
            fileList: [],
            value:''
        };
        this.handleChange = this.handleChange.bind(this);
        this.handleCancel = this.handleCancel.bind(this);
        this.beforeUpload = this.beforeUpload.bind(this);
        this.onChangeRadioSelect=this.onChangeRadioSelect.bind(this);
    }
    handleChange(info) {
        let { file, fileList } = info;
        if (file.status == 'error') {
            Modal.error({
                centered: true,
                title: '上传失败',
                content: file.response.message
            });
            return;
        }
        fileList = fileList.map((file) => {
            if (file.response) {
                file.url = file.response.downloadPath;
            }
            return file;
        });
        fileList = fileList.filter((file) => {
            return file.status === 'done';
        });
        this.setState({
            fileList: [.
  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值