亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

解決el-upload批量上傳只執(zhí)行一次成功回調(diào)on-success的問(wèn)題

 更新時(shí)間:2023年03月28日 16:04:59   作者:小寶&  
這篇文章主要介紹了解決el-upload批量上傳只執(zhí)行一次成功回調(diào)on-success的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

el-upload批量上傳只執(zhí)行一次成功回調(diào)on-success

刪除掉:

file-list="fileList"

在網(wǎng)上找了下解決方法,發(fā)現(xiàn)取消file-list綁定即可,網(wǎng)上也有自定義的上傳事件的方法,不過(guò)這個(gè)操作起來(lái)更方便一些。

上面方法還是有點(diǎn)問(wèn)題,正確的方法是在后臺(tái)拉數(shù)據(jù)的時(shí)候,創(chuàng)建一個(gè)臨時(shí)變量filelist2,然后將后臺(tái)的數(shù)據(jù)filelist賦值給filelist2,再將filelist2綁定(:file-list="filelist2")

然后對(duì)數(shù)據(jù)的操作都在filelist中。

el-upload自定義上傳后回調(diào)上傳成功和失敗事件

template部分:

<el-upload
? class="el_upload_above"
? action=""
? ref="upload"
? :limit="limitnum"
? list-type="picture-card"
? :http-request="uploadSectionFile"
? :auto-upload="true"
? :file-list="fileList"
? :on-error="uploadFileError"
? :on-success="uploadFileSuccess"
? :on-exceed="exceedFile"
? :on-remove="removeFile">
</el-upload>

script部分:

<script>
? export default {
? ? data() {
? ? ? return {
? ? ? ?? ?fileList:[],//上傳的文件列表
? ? ? ?? ?limitnum:2,//最大允許上傳個(gè)數(shù)?
? ? ? };
? ? },
? ? methods: {
? ? ?? ?//自定義上傳
? ? ?? ?uploadSectionFile(param){
? ??? ??? ? ?var fileObj = param.file;
?? ? ? ? ?var form = new FormData();
?? ? ? ? ? // 文件對(duì)象
?? ? ? ? ?form.append("file", fileObj);
?? ? ? ? ?this.$axios.post('/file/upload',form).then(res => {
?? ? ? ? ? ?param.onSuccess(res)
?? ? ? ? ?}).catch(({err}) => {
?? ? ? ? ? ?param.onError(err)
?? ? ? ? ?}) ?
? ? ?? ?},
? ? ? ?? ?//上傳失敗
?? ? ? ?uploadFileError(err, file, fileList){
?? ? ? ? ?this.$message.error("上傳失敗!")
?? ? ? ?},
? ? ? ?? ?//上傳成功
?? ? ? ?uploadFileSuccess(response, file, fileList){
?? ? ? ? ?if(response.data.error==0){
?? ? ? ? ? ?file.response=response.data.data;
?? ? ? ? ? ?this.fileList.push(file)
?? ? ? ? ?}else{
?? ? ? ? ? ?this.$message.error(response.data.message);//文件上傳錯(cuò)誤提示
?? ? ? ? ?}
?? ? ? ?},
?? ? ? ?// 文件超出個(gè)數(shù)限制時(shí)的鉤子
?? ? ? ?exceedFile(files, fileList){
?? ? ? ? ?this.$message.error('只能上傳'+this.limitnum+'個(gè)文件');
?? ? ? ?},
?? ? ? ?//刪除文件
?? ? ? ?removeFile(file,fileList) {
?? ? ? ? ?this.fileList=fileList;
?? ? ? ?},
? ? }
? }
</script>

注釋

自定義上傳后,成功和失敗需要在自定義上傳代碼中觸發(fā)(onSuccess / onError)。在組件部分需要寫(xiě)文件上傳或失敗的回調(diào)事件(uploadFileSuccess / uploadFileError)

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論