zoukankan      html  css  js  c++  java
  • ant design for vue 上传文件

    1、使用customRequest

    customRequest 通过覆盖默认的上传行为,可以自定义自己的上传实现 Function

    定义customRequest,之前定义action行为会被覆盖,可以注释掉

    <a-upload
            name="file"
            :multiple="false"
            @change="changeFile"
            :customRequest="customRequest"
          >
            <a-button type="primary"> <a-icon type="upload" />导入Excel</a-button>
    </a-upload>

     

    changeFile(info) { // 上传文件
            if (info.file.status !== 'uploading') {
              console.log(info.file, info.fileList);
            }
            if (info.file.status === 'done') {
              this.$message.success(`${info.file.name} 上传成功`);
            } else if (info.file.status === 'error') {
              this.$message.error(`${info.file.name} 上传失败.`);
            }
     },
    customRequest(data){ // 上传提交
    const formData = new FormData()
    formData.append('file', data.file)
    formData.append('token', "token")
      this.saveFile(formData)
    },
    saveFile (formData) {
    this.axios({
    method: 'post',
    url: '/api/saveFile',
    headers: {
    },
    params:{
    },
    data: formData
    }).then((response) => {
    console.log(response)
    }).catch(function (error) {
    console.log(error)
    })

    },

      

  • 相关阅读:
    【FZYZOJ】细菌 题解(最短路)
    oracle 开发 第02章 查询
    oracle 开发 第01章 简介
    rhel配置163、epel、rpmforge的yum源
    linux 手动清除缓存
    查看linux内核版本和发行版本
    linux下安装rlwrap
    linux下安装vncserver
    Nagios 安装
    linux mutt发送报表
  • 原文地址:https://www.cnblogs.com/sllzhj/p/11683477.html
Copyright © 2011-2022 走看看