fix: 修复upload组件中事件拿到files为空的bug

This commit is contained in:
wanchun 2021-05-23 10:51:31 +08:00
parent 60e70f9ea4
commit fd64419b6e
3 changed files with 11 additions and 9 deletions

View File

@ -8,7 +8,7 @@
<Row class="panel"> <Row class="panel">
<Cell class="son-panel" span="12"> <Cell class="son-panel" span="12">
<div class="panel-case"> <div class="panel-case">
<Upload v-for="(item, index) in data" :max-size="10" :key="index" :accept="option.accept" :action="action"> <Upload v-for="(item, index) in data" url="test" @on-fail="fail" :max-size="10" :key="index" :accept="option.accept" >
<!-- <Wb-button>点击上传{{ item.url }}</Wb-button> --> <!-- <Wb-button>点击上传{{ item.url }}</Wb-button> -->
</Upload> </Upload>
</div> </div>
@ -133,11 +133,11 @@ export default {
}, },
methods: { methods: {
sucess(file, result, arg) { sucess(file, result, arg) {
}, },
fail() { fail(files, status) {
console.log(arguments) console.log(files)
} }
} }
} }
</script> </script>

View File

@ -1,6 +1,6 @@
{ {
"name": "@webank/fes-ui", "name": "@webank/fes-ui",
"version": "0.4.9", "version": "0.4.10",
"description": "基于Vue2.0适用于PC管理端的组件库", "description": "基于Vue2.0适用于PC管理端的组件库",
"main": "dist/fes-ui.js", "main": "dist/fes-ui.js",
"scripts": { "scripts": {

View File

@ -133,8 +133,10 @@ export default {
const files = e.target.files; const files = e.target.files;
const len = files.length; const len = files.length;
const validateArray = []; const validateArray = [];
const validateFiles = [];
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
const file = e.target.files[i]; const file = e.target.files[i];
validateFiles.push(file);
validateArray.push(this.validate(file)); validateArray.push(this.validate(file));
} }
Promise.all(validateArray).then( Promise.all(validateArray).then(
@ -159,12 +161,12 @@ export default {
) { ) {
try { try {
const result = JSON.parse(xhr.responseText); const result = JSON.parse(xhr.responseText);
this.$emit('on-success', files, result); this.$emit('on-success', validateFiles, result);
} catch (e1) { } catch (e1) {
console.error('响应格式不正确'); console.error('响应格式不正确');
} }
} else { } else {
this.$emit('on-fail', files, xhr.status); this.$emit('on-fail', validateFiles, xhr.status);
} }
this.$refs.input.value = ''; this.$refs.input.value = '';
} }
@ -179,7 +181,7 @@ export default {
if (this.action) { if (this.action) {
this.action(false); this.action(false);
} else { } else {
this.$emit('on-fail', files, -1); this.$emit('on-fail', validateFiles, -1);
} }
} }
); );