multi-uploader.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <div class="multi-uploader">
  3. <el-upload
  4. action="/upload_image"
  5. list-type="picture-card"
  6. :limit="9"
  7. :file-list="fileList"
  8. :on-preview="handlePictureCardPreview"
  9. :on-remove="handleRemove"
  10. :on-success="handleSuccess"
  11. >
  12. <i class="el-icon-plus"></i>
  13. </el-upload>
  14. <el-dialog :visible.sync="dialogVisible">
  15. <img width="100%" :src="dialogImageUrl" alt />
  16. </el-dialog>
  17. <div slot="tip" class="el-upload__tip">最多添加9张作品图片</div>
  18. </div>
  19. </template>
  20. <script>
  21. export default {
  22. name: "multi-uploader",
  23. props: {
  24. value: Array
  25. },
  26. model: {
  27. prop: "value",
  28. event: "change"
  29. },
  30. components: {},
  31. data() {
  32. return {
  33. uploading: false,
  34. fileList: [],
  35. dialogImageUrl: "",
  36. dialogVisible: false
  37. };
  38. },
  39. computed: {},
  40. mounted() {
  41. this.fileList = this.value;
  42. },
  43. methods: {
  44. handleRemove(file, fileList) {
  45. console.log(file, fileList);
  46. this.handleChange(fileList);
  47. },
  48. handlePictureCardPreview(file) {
  49. this.dialogImageUrl = file.url;
  50. this.dialogVisible = true;
  51. },
  52. handleSuccess(response, file, fileList) {
  53. console.log(response, file, fileList);
  54. this.handleChange(fileList);
  55. },
  56. handleChange(fileList) {
  57. const list = [];
  58. fileList.map(file => {
  59. list.push({
  60. name: file.name,
  61. url: file.response ? file.response.filename : file.url
  62. });
  63. });
  64. console.log(list, fileList);
  65. this.$emit("change", list);
  66. }
  67. }
  68. };
  69. </script>
  70. <style lang="scss">
  71. .multi-uploader {
  72. position: relative;
  73. background: #fff;
  74. }
  75. </style>