waterfall-item.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <view class="waterfall-item-container">
  3. <view class="waterfall-item" @tap="onTap">
  4. <image :src="params.url" mode="widthFix" @load="emitHeight" @error="emitHeight"></image>
  5. <view class="content">
  6. <view>{{params.title}}</view>
  7. <view class="money">{{params.money}}元</view>
  8. <view style="margin: 0 0 8rpx 0;">
  9. <text class="label">{{params.label}}</text>
  10. </view>
  11. <view class="shop-name">{{params.shop}}</view>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. name:"helangWaterfallItem",
  19. options:{
  20. virtualHost: true
  21. },
  22. props:{
  23. params:{
  24. type: Object,
  25. default(){
  26. return {}
  27. }
  28. },
  29. tag:{
  30. type:String | Number,
  31. default:''
  32. },
  33. index:{
  34. type:Number,
  35. default:-1
  36. }
  37. },
  38. data() {
  39. return {
  40. };
  41. },
  42. methods:{
  43. // 发出组件高度信息,在此处可以区分正确和错误的加载,给予错误的提示图片
  44. emitHeight(e){
  45. const query = uni.createSelectorQuery().in(this);
  46. query.select('.waterfall-item-container').boundingClientRect(data => {
  47. let height = Math.floor(data.height);
  48. this.$emit("height",height,this.$props.tag);
  49. }).exec();
  50. },
  51. onTap(){
  52. this.$emit("click",this.$props.index,this.$props.tag);
  53. }
  54. }
  55. }
  56. </script>
  57. <style lang="scss" scoped>
  58. .waterfall-item{
  59. padding: 16rpx;
  60. background-color: #fff;
  61. border-radius: 4px;
  62. font-size: 28rpx;
  63. color: #666;
  64. image{
  65. display: block;
  66. width: 100%;
  67. // 默认设置一个图片的大约值
  68. height: 350rpx;
  69. }
  70. .content{
  71. margin-top: 16rpx;
  72. .money{
  73. color: #fa3534;
  74. margin-top: 8rpx;
  75. }
  76. .label{
  77. background-color: #fa3534;
  78. color: #fff;
  79. font-size: 20rpx;
  80. padding: 4rpx 16rpx;
  81. border-radius: 20rpx;
  82. }
  83. .shop-name{
  84. font-size: 20rpx;
  85. color: #999;
  86. }
  87. }
  88. }
  89. </style>