前端最终规范


element ui upload 多个文件一次上传

<pre><code class="language-markdown">&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt; &lt;link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"&gt; &lt;title&gt;Document&lt;/title&gt; &lt;style&gt; .progress{ width:100%; height:10px; border:1px solid #ccc; border-radius: 10px; } .point{ /* width:100px; */ height:100%; background: red; border-radius: 10px; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="app"&gt; &lt;el-upload class="upload-demo" action="https://jsonplaceholder.typicode.com/posts/" :on-preview="handlePreview" :on-remove="handleRemove" :before-remove="beforeRemove" :auto-upload="false" ref="upload" multiple :limit="3" :on-success="handleSuccess" :on-error="handleError" :on-exceed="handleExceed" :on-progress="handleProgress" :show-file-list="false" :on-change="onChange" :http-request="httpRequest" :before-upload="beforeUpload" :file-list="fileList"&gt; &lt;el-button size="small" type="primary"&gt;点击上传&lt;/el-button&gt; &lt;div slot="tip" class="el-upload__tip"&gt;只能上传jpg/png文件,且不超过500kb&lt;/div&gt; &lt;/el-upload&gt; &lt;el-button size="small" type="primary" @click="submitUpload"&gt;开始上传文件&lt;/el-button&gt; &lt;progress-line :progress="data.progress" v-for="data in fileData" /&gt; &lt;/div&gt; &lt;/body&gt; &lt;script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"&gt;&lt;/script&gt; &lt;script src="https://unpkg.com/element-ui/lib/index.js"&gt;&lt;/script&gt; &lt;script src="https://unpkg.com/axios/dist/axios.min.js"&gt;&lt;/script&gt; &lt;template id="count"&gt; &lt;div class="progressLine"&gt; &lt;p&gt;文件进度展示&lt;/p&gt; &lt;div&gt; &lt;div class="progress"&gt; &lt;div class="point" :style="{width:progress + '%'}" &gt;&lt;/div&gt; &lt;/div&gt;&lt;span&gt;{{progress}}% &lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;/template&gt; &lt;script&gt; Vue.component('progress-line',{ template:"#count", props:{ progress:{ type:Number, default:30 } }, }) new Vue({ el:"#app", data(){ return{ fileList: [], fileData:new FormData(), // fileData: new FormData() } }, methods:{ startUpload(){ this.$refs.upload.submit() }, submitUpload(){ this.$refs.upload.submit() axios.post('https://jsonplaceholder.typicode.com/posts/',this.fileData,{ onUploadProgress: progressEvent =&gt; { let percent=(progressEvent.loaded / progressEvent.total * 100) | 0 console.log('percent',percent) } }) }, httpRequest(event){ console.log(event) this.fileData.append('file',event.file) }, handleRemove(file, fileList) { console.log(file, fileList); }, handlePreview(file) { console.log(file); }, handleExceed(files, fileList) { this.$message.warning(`当前限制选择 3 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`); }, beforeRemove(file, fileList) { return this.$confirm(`确定移除 ${ file.name }?`); }, handleSuccess(response, file, fileList){ console.log('fileData',this.fileData) }, handleError(err, file, fileList){ console.log('handleError',err, file, fileList) }, handleProgress(event, file, fileList){ let index=this.fileData.findIndex(_=&gt;_.uid===file.uid); if(index+1){ this.fileData[index].progress=Math.floor(event.percent) } console.log('this.fileData[index]',this.fileData[index]) }, onChange(file, fileList){ console.log('onChange',file, fileList) }, beforeUpload(event){ return true; } } }) &lt;/script&gt; &lt;/html&gt;</code></pre>

页面列表

ITEM_HTML