ant-upload上传成功

简介: ant-upload上传成功

ant-upload上传成功

<template>
  <div>
    <a-upload
      name="file"
      :multiple="true"
      :action="path"
      :headers="headers"
      :beforeUpload="beforeUploadMains"
      :default-file-list="fileList"
      @change="handleChange"
    >
      <a-button size="small"> <a-icon type="upload" /> 上传文件 </a-button>
    </a-upload>
  </div>
</template>
<script>
export default {
   
  name: 'singleUpload',
  props: {
   
    fileList: Array,
  },
  data() {
   
    return {
   
      path: `${
   process.env.VUE_URL}/aaaaa`,
      headers: {
   
        authorization: 'authorization-text',
        token: JSON.parse(localStorage.getItem('pro__Access-Token')).value
      },
    }
  },
  methods: {
   
    beforeUploadMains(file) {
   
      return new Promise((resolve, reject) => {
   
        // console.log(file)
        if (file.name.substr(-4) !== 'doc') {
   
          this.$message.warning('上传文件只能是doc格式!')
          return reject(false)
        } else {
   
          resolve(true)
        }
        const isLt10M = file.size / 1024 / 1024 < 10
        if (!isLt10M) {
   
          this.$message.warning('上传文件大小不能超过 10MB!')
          return reject(false)
        } else {
   
          resolve(true)
        }
      })
    },
    handleChange(info) {
   
      if(info.file.status == "done"){
   
        if(info.file.response.status == '1'){
   
          this.$message.success('文件上传成功!')
          let datas = info.file.response.data
          this.$emit('onSuccess', datas)
        } else {
   
          this.$message.warning('上传文件为不可解析文件!')
        }
      }
    },
  },
}
</script>
目录
相关文章
|
2月前
ant-design Upload上传组件使用 编辑功能图片回显
ant-design Upload上传组件使用 编辑功能图片回显
347 0
|
8月前
LayUI upload上传组件上传文件的两种方式
LayUI upload上传组件上传文件的两种方式
485 0
|
存储 API Python
FastAPI(24)- 详解 File,上传文件
FastAPI(24)- 详解 File,上传文件
1032 0
FastAPI(24)- 详解 File,上传文件
|
11月前
|
JavaScript
VUE上传功能本地上传正常,打包上传后报错TypeError: ***.upload.addEventListener is not a function
VUE上传功能本地上传正常,打包上传后报错TypeError: ***.upload.addEventListener is not a function
461 0
|
前端开发 JavaScript
Bootstrap File Input,最好用的文件上传组件(1)
Bootstrap File Input,最好用的文件上传组件
581 0
Bootstrap File Input,最好用的文件上传组件(1)
|
2月前
|
Java Spring
DWR上传文件提示File uploads not supported
确保你的DWR配置和代码都正确地支持文件上传,以解决"DWR上传文件提示File uploads not supported" 错误。
17 0
|
2月前
|
移动开发 JavaScript 小程序
uView Upload 上传
uView Upload 上传
31 0
|
7月前
|
小程序 应用服务中间件 Shell
laravel8(三)文件上传提示 “The file deos not exits ” ,但确实已经上传了文件
Laravel 文件上传提示 “The file "" deos not exits ” ,但确实已经上传了文件
46 1
|
2月前
|
存储
ant-design Upload上传组件使用 action上传
ant-design Upload上传组件使用 action上传
193 0
Cypress系列(100)- cypress-file-upload 插件, attachFile() 命令详解
Cypress系列(100)- cypress-file-upload 插件, attachFile() 命令详解
355 0
Cypress系列(100)- cypress-file-upload 插件, attachFile() 命令详解