imageList.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <div class="wrap flex row">
  3. <i class="el-icon-arrow-left" @click="scroll(-1)"></i>
  4. <div class="list" ref="list">
  5. <el-image
  6. class="image" v-for="(item, index) of data" :key="index" :src="item.cdn_url" fit="cover"
  7. @click="handleViwer(index)"></el-image>
  8. </div>
  9. <i class="el-icon-arrow-right" @click="scroll(1)"></i>
  10. <ElImageViewer v-if="showViewer" :initial-index="currentPre" :on-close="closeViewer" :url-list="comImg" />
  11. </div>
  12. </template>
  13. <script>
  14. import ElImageViewer from "element-ui/packages/image/src/image-viewer";
  15. export default {
  16. components: { ElImageViewer },
  17. props: {
  18. data: {
  19. type: Array,
  20. default: () => {
  21. return []
  22. },
  23. }
  24. },
  25. data() {
  26. return {
  27. currentPre: 0,
  28. showViewer: false,
  29. }
  30. },
  31. computed: {
  32. comImg() {
  33. return this.data.map(i => i.cdn_url);
  34. }
  35. },
  36. methods: {
  37. scroll(amount) {
  38. const list = this.$refs.list;
  39. list.scrollLeft += amount * list.clientWidth;
  40. },
  41. closeViewer() {
  42. this.showViewer = false;
  43. },
  44. handleViwer(i) {
  45. this.currentPre = i;
  46. this.showViewer = true;
  47. }
  48. }
  49. };
  50. </script>
  51. <style lang="scss" scoped>
  52. .wrap {
  53. transition: padding 0.3s ease;
  54. &:hover i {
  55. opacity: 1;
  56. }
  57. }
  58. i {
  59. cursor: pointer;
  60. opacity: 0;
  61. transition: opacity 0.3s ease;
  62. }
  63. .wrap .list {
  64. width: 330px;
  65. overflow-x: hidden;
  66. white-space: nowrap;
  67. scroll-behavior: smooth;
  68. }
  69. .image {
  70. width: 100px;
  71. height: 100px;
  72. margin-top: 10px;
  73. margin-right: 10px;
  74. cursor: pointer;
  75. }</style>