上传文件(二)

<template>
  <div>
    <el-upload
      action="https://jsonplaceholder.typicode.com/posts/"
      list-type="picture-card"
      :auto-upload="false"
      :limit="9"
      :on-preview="handlePictureCardPreview"
      :on-remove="handleRemove"
      :http-request="uploadFile"
      ref="upload"
      accept="image/png,image/gif,image/jpg,image/jpeg"
    >
      <i class="el-icon-plus"></i>
    </el-upload>
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>
    <el-button type="primary" @click="subPicForm">上传</el-button>
  </div>
</template>

<script>
export default {
  name: 'UpFiles',
  data () {
    return {
      dialogImageUrl: '',
      dialogVisible: false,
      formData: ''
    }
  },
  methods: {
    uploadFile (file) {
      this.formData.append('file', file.file)
    },
    handlePictureCardPreview (file) {
      this.dialogImageUrl = file.url
      this.dialogVisible = true
    },
    handleRemove (file, fileList) {
      console.log(file, fileList)
    },
    subPicForm () {
      this.formData = new FormData()
      this.$refs.upload.submit()
      this.formData.append('WS_CODE', '12133')
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }
      this.$axios.post('/api/upload', this.formData, config).then(res => {
        console.log(res)
      }).catch(res => {
        console.log(res.response.status)
      })
    }
  }
}
</script>

<style scoped>

</style>

 

上一篇:C# 合并PDF 下载


下一篇:山东大学项目实训审计系统(五)上传文件