当前位置:   article > 正文

基于vue-simple-uploader的文件分片上传_vue-simple-uploader配置categorymap

vue-simple-uploader配置categorymap
  1. <template>
  2. <div class="main_con">
  3. <uploader
  4. :options="options"
  5. :file-status-text="statusText"
  6. class="uploader-example"
  7. ref="uploader"
  8. @file-success="fileSuccess"
  9. @file-error="onFileError"
  10. @file-removed="fileRemoved"
  11. style="width: 100%;"
  12. >
  13. <uploader-unsupport></uploader-unsupport>
  14. <uploader-drop>
  15. <uploader-btn>选择文件</uploader-btn>
  16. </uploader-drop>
  17. <uploader-list></uploader-list>
  18. </uploader>
  19. </div>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. options: {
  26. target: '/file' + '/minio/upload', // 上传地址
  27. testChunks: false, //是否开启服务器分片校验
  28. maxChunkRetries: 5, //最大自动失败重试上传次数
  29. chunkSize: 1 * 1024 * 1024, //分片大小 这里设置10M
  30. singleFile: false, //单文件上传
  31. query: {
  32. fileType: 2, //传参
  33. fileDirName: 'imgs/',
  34. },
  35. categoryMap: {
  36. accept: ['.png', '.jpg', '.jpeg', '.gif', '.pdf', '.mp4'], //接受文件类型
  37. },
  38. headers: {
  39. // 在header中添加的验证,请根据实际业务来
  40. Authorization: 'Bearer ' + sessionStorage.getItem('access_token'),
  41. },
  42. },
  43. statusText: {
  44. success: '上传成功',
  45. error: '上传失败',
  46. uploading: '上传中',
  47. paused: '暂停中',
  48. waiting: '等待中',
  49. },
  50. }
  51. },
  52. mounted() {
  53. // 获取uploader对象
  54. this.$nextTick(() => {
  55. window.uploader = this.$refs.uploader.uploader
  56. })
  57. },
  58. methods: {
  59. //上传成功返回的信息
  60. fileSuccess(rootFile, file, message, chunk) {
  61. console.log(message)
  62. },
  63. // 上传错误触发,文件还未传输到后端
  64. onFileError(rootFile, file, response, chunk) {
  65. console.log(rootFile, file, response, chunk)
  66. },
  67. // 移除文件
  68. fileRemoved(file) {
  69. },
  70. },
  71. }
  72. </script>

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