App.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <uploader
  3. :options="options"
  4. :file-status-text="statusText"
  5. class="uploader-example"
  6. ref="uploaderRef"
  7. @file-complete="fileComplete"
  8. @complete="complete"
  9. ></uploader>
  10. </template>
  11. <script>
  12. import { nextTick, ref, onMounted } from 'vue'
  13. export default {
  14. setup () {
  15. const uploaderRef = ref(null)
  16. const options = {
  17. target: '//localhost:3000/upload', // '//jsonplaceholder.typicode.com/posts/',
  18. testChunks: false
  19. }
  20. const attrs = {
  21. accept: 'image/*'
  22. }
  23. const statusText = {
  24. success: '成功了',
  25. error: '出错了',
  26. uploading: '上传中',
  27. paused: '暂停中',
  28. waiting: '等待中'
  29. }
  30. const complete = function () {
  31. console.log('complete', arguments)
  32. }
  33. const fileComplete = function () {
  34. console.log('file complete', arguments)
  35. }
  36. onMounted(() => {
  37. nextTick(() => {
  38. window.uploader = uploaderRef.value.uploader
  39. })
  40. })
  41. return {
  42. uploaderRef,
  43. options,
  44. attrs,
  45. statusText,
  46. complete,
  47. fileComplete
  48. }
  49. }
  50. }
  51. </script>
  52. <style>
  53. .uploader-example {
  54. width: 880px;
  55. padding: 15px;
  56. margin: 40px auto 0;
  57. font-size: 12px;
  58. box-shadow: 0 0 10px rgba(0, 0, 0, .4);
  59. }
  60. .uploader-example .uploader-btn {
  61. margin-right: 4px;
  62. }
  63. .uploader-example .uploader-list {
  64. max-height: 440px;
  65. overflow: auto;
  66. overflow-x: hidden;
  67. overflow-y: auto;
  68. }
  69. </style>