imgList.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <view class='img-list'>
  3. <view @click="img(item,index)" v-for="(item,index) in imgData" :key="index" class="img-list-item">
  4. <view @click.stop="goList" v-if="list.length - 5 == index && list.length > 6 " class="img-list-item-bgc">
  5. + {{list.length - 6}}
  6. </view>
  7. <image style="width: 100%;height: 100%; border-radius: 10rpx;" :src="item" mode=""></image>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. name: "imgList",
  14. props: {
  15. list: {
  16. type: Array,
  17. default: () => []
  18. }
  19. },
  20. data() {
  21. return {
  22. };
  23. },
  24. methods: {
  25. img(item, index) {
  26. uni.previewImage({
  27. urls: this.list, //需要预览的图片http链接列表,多张的时候,url直接写在后面就行了
  28. current: index, // 当前显示图片的http链接,默认是第一个
  29. success: function(res) {},
  30. fail: function(res) {},
  31. complete: function(res) {},
  32. })
  33. },
  34. goList(){
  35. this.$emit('click')
  36. }
  37. },
  38. computed: {
  39. imgData() {
  40. let arr = []
  41. if (this.list.length > 6) {
  42. arr = this.list.slice(0, 6)
  43. return arr
  44. } else {
  45. arr = this.list
  46. return arr
  47. }
  48. }
  49. }
  50. }
  51. </script>
  52. <style lang="scss" scoped>
  53. .img-list {
  54. width: 100%;
  55. display: flex;
  56. flex-wrap: wrap;
  57. }
  58. .img-list-item {
  59. margin-bottom: 20rpx;
  60. margin-right: 25rpx;
  61. position: relative;
  62. width: 192rpx;
  63. height: 192rpx;
  64. border-radius: 10rpx;
  65. overflow: hidden;
  66. .img-list-item-bgc {
  67. width: 100%;
  68. height: 100%;
  69. position: absolute;
  70. left: 0;
  71. top: 0;
  72. background-color: rgba(0, 0, 0, .5);
  73. z-index: 111;
  74. color: #fff;
  75. display: flex;
  76. justify-content: center;
  77. align-items: center;
  78. font-size: 48rpx;
  79. }
  80. }
  81. .img-list-item:nth-child(3n) {
  82. margin-right: 0;
  83. }
  84. </style>