photo.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <view>
  3. <view v-if="photos.length > 0">
  4. <view v-if="showType == 'big'" class="show-big-photo">
  5. <image @click="showPic" v-for="(item,index) in photos" :key="index" :data-index="index" :src="item" mode="aspectFill"></image>
  6. </view>
  7. <view v-if="showType == 'mid'" class="show-mid-photo flex alcenter space">
  8. <image @click="showPic" v-for="(item,index) in photos" :key="index" :data-index="index" :src="item" mode="aspectFill"></image>
  9. </view>
  10. <view v-if="showType == 'small'" class="show-small-photo flex space wrap">
  11. <image @click="showPic" v-for="(item,index) in photos" :key="index" :data-index="index" :src="item" mode="aspectFill"></image>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default{
  18. props:{
  19. photos:{
  20. type:Array,
  21. default:function(){
  22. return new Array;
  23. }
  24. }
  25. },
  26. computed:{
  27. showType(){
  28. if(this.photos.length == 1) return 'big';
  29. if(this.photos.length == 2) return 'mid';
  30. return 'small';
  31. }
  32. },
  33. data(){
  34. return {
  35. }
  36. },
  37. methods:{
  38. showPic(e){
  39. let index = parseInt(e.currentTarget.dataset.index);
  40. uni.previewImage({
  41. current:index,
  42. urls:this.photos
  43. });
  44. }
  45. }
  46. }
  47. </script>
  48. <style>
  49. .show-big-photo image{
  50. width: 100%;
  51. height: 400rpx;
  52. background: #F2F2F2;
  53. }
  54. .show-mid-photo image{
  55. width: calc(50% - 8rpx);
  56. height: 300rpx;
  57. background: #F2F2F2;
  58. }
  59. .show-small-photo image{
  60. width: 190rpx;
  61. height: 190rpx;
  62. background: #F2F2F2;
  63. border-radius: 8rpx;
  64. }
  65. .show-small-photo image:nth-child(n+4){
  66. margin-top: 16rpx;
  67. }
  68. </style>