photo.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view class="photo_list">
  3. <view class="title">全部<view class="red">({{photoList.length}})</view></view>
  4. <view class="photo">
  5. <view v-for="(item,index) in photoList" :key="index" class="photo_item" :data-index="index">
  6. <image mode="aspectFill" :src="item.imgPath" :data-src="item.imgPath" @tap="openImage"></image>
  7. </view>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. let app = getApp();
  13. import api from "../../../../../api.js"
  14. export default {
  15. data() {
  16. return {
  17. url:app.globalData.url,
  18. photoList:[],
  19. }
  20. },
  21. mounted() {
  22. this.getData();
  23. },
  24. methods: {
  25. //加载数据
  26. getData(){
  27. let data = {
  28. id:1757
  29. }
  30. api.getShopPhoto(data).then((res)=>{
  31. console.log(res);
  32. let data = res.data.data;
  33. let url = this.url;
  34. for(let i = 0;i<data.length;i++){
  35. data[i].imgPath = url + data[i].imgPath
  36. }
  37. this.photoList = data
  38. })
  39. },
  40. //预览图片
  41. openImage(e){
  42. let current = e.target.dataset.src;
  43. let photoList = this.photoList;
  44. let imgUrl = [];
  45. for(let i = 0;i<photoList.length;i++){
  46. imgUrl.push(photoList[i].imgPath)
  47. }
  48. wx.previewImage({
  49. current:current,
  50. urls: imgUrl,
  51. })
  52. }
  53. }
  54. }
  55. </script>
  56. <style>
  57. page{
  58. width:100%;
  59. height:100%;
  60. }
  61. .photo_list{
  62. width:100%;
  63. overflow: hidden;
  64. padding:0 30rpx;
  65. box-sizing: border-box;
  66. border-top:1px solid #f2f2f2;
  67. }
  68. .title{
  69. font-size: 30rpx;
  70. color:#222222;
  71. margin-top:18rpx;
  72. }
  73. .red{
  74. font-size: 30rpx;
  75. color:#E11521;
  76. display: inline-block;
  77. margin-left: 20rpx;
  78. }
  79. .photo{
  80. width:100%;
  81. margin-top:20rpx;
  82. overflow: hidden;
  83. }
  84. .photo_item{
  85. width:calc(50% - 6rpx);
  86. height:198rpx;
  87. margin:0 6rpx 10rpx 0;
  88. float:left;
  89. position: relative;
  90. overflow: hidden;
  91. }
  92. .photo_item:nth-child(2n){
  93. margin-right: 0;
  94. margin-left: 6rpx
  95. }
  96. .photo_item image{
  97. display: block;
  98. width:100%;
  99. height:100%;
  100. position: absolute;
  101. top:50%;
  102. left: 50%;
  103. transform: translate(-50%,-50%);
  104. }
  105. </style>