仿大众点评——tab切换、部分数据的显示与隐藏

在这里插入图片描述
在这里插入图片描述

代码

template
<template>
  <div id="app">
    <div v-for="(index,key) in GroupBuying" v-bind:key="'one'+key">
      <div class="GroupName">{{index.GroupName}}</div>
      <div v-if="show[key]==false">
        <div v-for="(item,k) in index.GroupType" v-bind:key="'two'+k">
          <div class="GroupBorder" v-if="k<2">
            <div class="GroupContent">
              <img class="GroupImg" :src="item.GroupRestaurantImg" />
            </div>
            <div class="GroupIntroduce">
              <div class="GroupIntru">{{item.GroupRestaurantType}}</div>
              <div class="GroupPrice">
                <span class="nowPrice">¥{{item.GroupRestaurantNewPrice}}</span>
                <span class="oldPrice">¥{{item.GroupRestaurantOldPrice}}</span>
                <div class="GroupSold">已售{{item.GroupRestaurantTypeSold}}</div>
              </div>
            </div>
          </div>
        </div>
        <div class="GroupHidden" @click="shows(key)">
          还有{{index.GroupType.length-2}}个团购
          <span
            class="iconfont icon-xiangxia"
            style="font-size: 14px;"
          ></span>
        </div>
        <div class="nulls"></div>
      </div>
      <div v-else>
        <div class="GroupBorder" v-for="(item,k1) in index.GroupType" v-bind:key="'three'+k1">
          <div class="GroupContent">
            <img class="GroupImg" :src="item.GroupRestaurantImg" />
          </div>
          <div class="GroupIntroduce">
            <div class="GroupIntru">{{item.GroupRestaurantType}}</div>
            <div class="GroupPrice">
              <span class="nowPrice">¥{{item.GroupRestaurantNewPrice}}</span>
              <span class="oldPrice">¥{{item.GroupRestaurantOldPrice}}</span>
              <div class="GroupSold">
                已售{{item.GroupRestaurantTypeSold}}
                <span
                  class="iconfont icon-xiangxia"
                  style="font-size: 14px;"
                ></span>
              </div>
            </div>
          </div>
        </div>
        <div class="nulls"></div>
      </div>
    </div>
  </div>
</template>
script

在对show数组进行设置的时候,需要同时设置get和set方法,否则会报错,但是对数据没有影响

<script>
import { mapState } from "vuex";
export default {
  created() {
    this.$store.dispatch("getGroupBuying");
  },
  data() {
    return {};
  },
  methods: {
    shows(key) {
      this.show[key] = true;
      this.$forceUpdate();
    }
  },
  computed: {
    ...mapState(["GroupBuying"]),
    show: {
      get: function() {
        var temp = [];
        for (var i = 0; i < this.GroupBuying.length; i++) {
          temp.push(false);
        }
        return (this.show = temp);
      },
      set: function() {}
    }
  }
};
</script>
style

通过使用 display: -webkit-box;可将页面的拉缩进行很好的设置

<style lang="less" scoped>
#app {
  font-family: Hiragino Sans GB, Arial, Helvetica, "宋体", sans-serif;
  .GroupName {
    border-bottom: 1px solid #f0f0f0;
    font-size: 16px;
    line-height: 46px;
    color: #333;
    padding: 0 12px 0 13px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
  }
  .GroupBorder {
    padding: 10px 10px 8px;
    display: -webkit-box;
    border-bottom: 1px solid #f0f0f0;
    .GroupContent {
      position: relative;
      .GroupImg {
        height: 66px;
        width: 90px;
        border-radius: 3px;
        margin-right: 10px;
      }
    }
    .GroupIntroduce {
      -webkit-box-flex: 1;
      .GroupIntru {
        font-size: 14px;
        line-height: 15px;
        max-height: 30px;
        color: #666;
        margin: 11px 0 14px;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
      }
      .GroupPrice {
        .nowPrice {
          color: #f63;
          margin-right: 5px;
          font-size: 18px;
        }
        .oldPrice {
          color: #999;
          font-size: 14px;
          text-decoration: line-through;
        }
        .GroupSold {
          text-align: right;
          color: #999;
          font-size: 12px;
          margin: -20px 14px;
        }
      }
    }
  }
  .GroupHidden {
    padding: 10px 0;
    text-align: center;
    color: #333;
    font-size: 14px;
    border-bottom: 1px solid #f0f0f0;
  }
  .nulls {
    height: 10px;
    background-color: #f0f0f0;
  }
}
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值