• 上传文件(二)


    <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>
  • 相关阅读:
    VC++读写文件
    VC++编译说明
    VC++时间函数总结
    VC++多工程项目
    VC++全局变量初始化
    Linux 系统免密码登陆远程服务器
    debian 系统安装配置apache
    数据库授权
    Mysql 主从服务器数据同步
    centos Install Docker
  • 原文地址:https://www.cnblogs.com/ronle/p/10995845.html
Copyright © 2020-2023  润新知