multi-uploader.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. if (file.response.filename && !file.response.error) {
  60. list.push({
  61. name: file.name,
  62. url: file.response ? file.response.filename : file.url
  63. });
  64. }
  65. });
  66. this.$emit("change", list);
  67. console.log("list:", list);
  68. console.log("fileList", fileList);
  69. console.log("this.fileList", this.fileList);
  70. }
  71. }
  72. };
  73. </script>
  74. <style lang="scss">
  75. .multi-uploader {
  76. position: relative;
  77. background: #fff;
  78. }
  79. </style>