vue tab切换

在这里插入图片描述

<template>
  <div>
    <div class="tab-bar clearfix">
      <div
        class="tab-bar_div"
        @click="tab(index)"
        v-for="(item,index) in items"
        :key="index"
        v-bind:class="{active : index===curId}"
      >{{item.item}}</div>
    </div>
    <div class="tab-con">
      <div
        class="rank-img"
        v-show="index===curId"
        v-for="(content, index) in contents"
        :key="index"
      >
        <div class="rank-first">
          <img :src="content.img" alt="">
        </div>
        <div class="rank-text">
          <div>
            <span>名称:</span>
            <span class="rank-name">{{content.name}}</span>
          </div>
          <div>
            <span>产地:</span>
            <span class="rank-name">{{content.addres}}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>

export default {
  name: "recommend",
  data() {
    return {
      curId: 0,
      items: [{ item: "昆明" }, { item: "大理" }, { item: "红河" }],
      contents: [
        {
          id: 0,
          img: require("../assets/image/img.png"),
          name: "大",
          addres: "昆明"
        },
        {
          id: 1,
          img: require("../assets/image/img.png"),
          name: "大111",
          addres: "大理"
        },
         {
          id: 2,
          img: require("../assets/image/img.png"),
          name: "大222",
          addres: "红河"
        }
      ],
      list: []
    };
  },
  created() {
  
  },
  methods: {
    tab(index) {
      this.curId = index;
    },

  }
};
</script>
<style lang="less">
.tab-bar {
  width: 100%;

  display: flex;
  overflow-y: auto;
}
.tab-bar_div {
  padding-left: 20px;
  padding-right: 20px;
  width: 100px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  text-decoration: none;
  color: #000;
}
.tab-bar .active {
  color: #f9493b;
  border-bottom: 2px solid #f9493b;
}
.tab-con div {
  text-align: left;
}
.rank-img {
  height: 115px;
  border-bottom: 1px solid #e8e2e2;
  margin: 16px;
  display: flex;
  justify-content: flex-start;
  .rank-first {
    width: 100px;
    height: 100px;
    margin-bottom: 16px;
    img {
      width: 100px;
      height: 100px;
    }
  }
  .rank-text {
    height: 100px;
    width: 100%;
    div {
      margin-top: 16px;
      margin-bottom: 16px;
      margin-left: 16px;
      .rank-name {
        color: #e23325d9;
        font-size: 15px;
      }
    }
  }
}
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值