欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vue tab切换

程序员文章站 2022-06-06 08:12:12
...

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>

上一篇: 从 Excel 到 Python

下一篇: Fiddler使用