<template> <div> <el-upload class="upload-demo" ref="upload" :multiple="false" action="void" :http-request="customUpload" :on-remove="handleRemove" :on-progress="progressA" :file-list="fileList" multiple :auto-upload="true"> <el-button slot="trigger" size="small" type="primary">選取文件</el-button> </el-upload> </div> </template> <script> export default { data() { return { fileList: [], } }, components: {}, mounted() { }, methods: { customUpload(file) { let FormDatas = new FormData(); FormDatas.append('file', file.file); this.$axios({ url: 'http://192.168.1.5:8889/upload', method: 'post', data: FormDatas, //上傳進度 onUploadProgress: (progressEvent) => { let num = progressEvent.loaded / progressEvent.total * 100 | 0; //百分比 file.onProgress({percent: num}) //進度條 } }).then(data => { file.onSuccess(); //上傳成功(打鉤的小圖標) }) }, /** 文件正在上傳時的鉤子 **/ progressA(event, file) {}, /** 移除上傳文件 **/ handleRemove(file) { this.$refs.upload.abort(); //取消上傳 this.$message({message: '成功移除' + file.name, type: 'success'}); }, }, } </script> <style> </style>