美文网首页
react 结合 upload 实现自定义展示缩略图

react 结合 upload 实现自定义展示缩略图

作者: lessonSam | 来源:发表于2021-02-19 19:30 被阅读0次

++如果是后端给我们的就需要后端加个字段 thumbUrl ,或者我们拿到URL 给数据添加字段 ++

componentDidUpdate(prevProps) {
    const { data } = this.props
    if (data && data !== prevProps.data) {
      let thumbnailData = this.getThumbnail(data)
      this.setState({
        fileList: thumbnailData
      })
    }
  }

  getThumbnail(data) {
    data.map((item, index) => {
      if (item.type == 1) {
        return (item.thumbUrl = defaultPicureImg)
      }
      if (item.type == 2) {
        return (item.thumbUrl = defaultVideoImg)
      }
      if (item.type == 3) {
        return (item.thumbUrl = defaultPDFImg)
      }
    })
    return data
  }

相关文章

网友评论

      本文标题:react 结合 upload 实现自定义展示缩略图

      本文链接:https://www.haomeiwen.com/subject/pmbdrktx.html