<template>
  <div>
    <el-upload
      action
      :on-change="updateReason"
      :auto-upload="false"
      accept=".json"
      list-type="multipart/form-data"
    >
      <el-button size="small" type="primary">阶段原因上传</el-button>
      <div slot="tip" class="el-upload__tip">只能上传JSON文件</div>
    </el-upload>
  </div>
</template>
<script>
import http from '../../lib/http' //(封装的axios)
export default {
  data() {
    return {
      fileList: [],
    }
  },
  methods: {
    updateReason(file, fileList) {
      this.fileTransmit(file, fileList)
    },
    fileTransmit(file, fileList, isShow) {
      this.fileList = fileList
      var reader = new FileReader() //新建一个FileReader
      reader.readAsText(file.raw, 'UTF-8') //读取文件
      reader.onload = async function(evt) { //读取文件完毕执行此函数
        let dataJson = JSON.parse(evt.target.result)
        let apiUrl = 'http://11.2.180.225:3003/searchplat/sample/user/updateReason'

        let { data } = await http.post(apiUrl, { json: dataJson })
        console.log(data)
      }
    },
  },
}
</script>

Logo

前往低代码交流专区

更多推荐