-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: FUpload组件 fileList 支持 v-model 双向绑定 (#336)
* fix: 解决上传组件,初始列表为空时清空无效的问题 * feat: upload组件 fileList 支持 v-model 双向绑定 * feat: upload组件,监听fileList变更逻辑优化
- Loading branch information
Showing
5 changed files
with
126 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<template> | ||
<FUpload | ||
action="https://run.mocky.io/v3/2d9d9844-4a46-4145-8f57-07e13768f565" | ||
multiple | ||
:multipleLimit="4" | ||
:fileList="fileList" | ||
:accept="accept" | ||
:beforeUpload="beforeUpload" | ||
@change="change" | ||
@remove="remove" | ||
@success="success" | ||
@error="error" | ||
@exceed="exceed" | ||
@progress="progress" | ||
> | ||
<template #tip> | ||
<div class="f-upload__tip"> | ||
只能上传 jpg/png 等图片文件,且不超过 5KB | ||
</div> | ||
</template> | ||
</FUpload> | ||
</template> | ||
<script> | ||
import { ref } from 'vue'; | ||
export default { | ||
setup() { | ||
const fileList = ref([ | ||
{ | ||
uid: '1', | ||
name: 'xxx.png', | ||
status: 'done', | ||
response: 'Server Error 500', // custom error message to show | ||
url: 'http://www.baidu.com/xxx.png', | ||
}, | ||
{ | ||
uid: '2', | ||
name: 'yyy.png', | ||
status: 'done', | ||
url: 'http://www.baidu.com/yyy.png', | ||
}, | ||
{ | ||
uid: '3', | ||
name: 'zzz.png', | ||
status: 'error', | ||
response: 'Server Error 500', // custom error message to show | ||
url: 'http://www.baidu.com/zzz.png', | ||
}, | ||
]); | ||
const accept = ['image/*']; | ||
const change = (param) => { | ||
console.log('change:', param); | ||
}; | ||
const remove = (param) => { | ||
console.log('remove:', param, fileList.value); | ||
}; | ||
const success = (param) => { | ||
console.log('success:', param, fileList.value); | ||
}; | ||
const error = (param) => { | ||
console.log('error:', param, fileList.value); | ||
}; | ||
const exceed = (param) => { | ||
console.log('exceed:', param); | ||
}; | ||
const progress = (param) => { | ||
console.log('progress:', param); | ||
}; | ||
const beforeUpload = async (file) => { | ||
console.log('file:', file); | ||
if (file.size > 500 * 1024) { | ||
console.log('超出5KB,无法上传!'); | ||
return false; | ||
} | ||
return true; | ||
}; | ||
return { | ||
fileList, | ||
accept, | ||
change, | ||
remove, | ||
success, | ||
error, | ||
exceed, | ||
progress, | ||
beforeUpload, | ||
}; | ||
}, | ||
}; | ||
</script> | ||
<style> | ||
.f-upload__tip { | ||
font-size: 12px; | ||
margin-top: 7px; | ||
color: #93949b; | ||
} | ||
</style> |