上传文件

<el-upload class="upload-demo" action accept=".mp4" :show-file-list="true" :auto-upload="false" :on-change="fileChange" :file-list="fileList">
      <el-button slot="trigger" size="small" type="primary" class="white">选择文件</el-button>
      <el-button class="blue" @click="video_upload">上传</el-button>
</el-upload>
upload() {
      const formData = new FormData(); //定义一个空的文件
      formData.append("file", this.files);  //添加参数,this.files轼通过  fileChange() 事件获取;需要几个参数就formData.append("参数名", 参数)几次
      uploadVideo(formData).then((res) => {  //调上传接口
        if (res.data.retMsg == "成功") {
          this.fileList = [];
          this.$message.success("上传成功");
        } else {
          this.$message.error("上传失败");
        }
      });
    },
posted @ 2023-07-14 16:14  就这样,  阅读(8)  评论(0编辑  收藏  举报