_a-upload不显示filelis">
当前位置:   article > 正文

Ant Design Vue 文件上传自定义按钮和文件列表位置_a-upload不显示filelist

a-upload不显示filelist

采用默认上传文件样式如下:

主要代码如下,可参照官方示例

  1. <a-upload
  2. name="file"
  3. style="float: left;"
  4. @change="uploadFile"
  5. :fileList="fileList"
  6. :showUploadList="false"
  7. :customRequest="customRequest">
  8. <a-button style="margin: 2px 2px;" icon="upload"></a-button>
  9. </a-upload>

想要固定button位置和上传文件列表展示位置, 思路为引用两个upload组件,一个带上传button,只负责上传文件操作,不显示文件列表;将文件列表数据赋值给另一个组件,另一个组件负责展示文件列表。两个组件分别置于两个div中,因此可以通过控制div样式来调整位置。关键代码如下:

  1. <!-- 上传文件-->
  2. <div class="list-button">
  3. <a-upload
  4. name="file"
  5. style="float: left;"
  6. @change="uploadFile"
  7. :fileList="fileList"
  8. :showUploadList="false" <!--设置该组件不显示文件列表-->
  9. :customRequest="customRequest">
  10. <a-button style="margin: 2px 2px;" icon="upload"></a-button>
  11. </a-upload>
  12. </div>
  13. <!-- 展示文件列表-->
  14. <div class="show-file-name">
  15. <a-upload
  16. style="float: left;width:100%"
  17. :fileList="showFileList" <!--设置该组件文件列表-->
  18. ></a-upload>
  19. </div>
  20. ...
  21. export default{
  22. data(){
  23. return{
  24. fileList:[],
  25. showFileList:[]
  26. }
  27. },
  28. methods:{
  29. uploadFile(info){
  30. // console.log("info:", info);
  31. let { fileList } = info;
  32. const status = info.file.status;
  33. if (status !== 'uploading') {
  34. console.log("uploading...",info.file, info.fileList);
  35. }
  36. if (status === 'done') {
  37. this.$message.success(`${info.file.name} file uploaded successfully`);
  38. } else if (status === 'error') {
  39. this.$message.error(`${info.file.name} file upload failed.`);
  40. }
  41. this.fileList = [...fileList].slice(-1); //只保留最新上传的一个文件
  42. this.showFileList = this.fileList; //文件列表赋值
  43. },
  44. }
  45. }
  46. ...css...

效果如下:

唉,之前也是调了老半天

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/339072
推荐阅读
相关标签
  

闽ICP备14008679号