Vue——tab栏切换增强版

  • 题目描述

    • 点击tab栏 内容区域显示对应的内容
    • 如 点击 SECTION 1 则 内容区域显示 对应 SECTION 1 的内容 同时当前 SECTION的字体颜色变成蓝色
  • 训练目标

  • 能够理解vue 中的数据渲染
  • 能够理解 v-for, v-if , v-bind , v-click 的使用
  • 能够理解 vue 中调用函数的时候传递参数
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #app {
        width: 100%;
      }
      div {
        width: 200px;
      }
      * {
        margin: 0;
        padding: 0;
      }
      .box {
        display: flex;
        justify-content: space-between;
        width: 800px;
        height: 150px;
        /* background-color: pink; */
        margin: 100px auto;
      }

      .content {
        width: 400px;
        /* background-color: blue; */
        border-left: 2px solid gray;
        border-right: 2px solid gray;
        display: none;
      }
      a {
        display: block;
        height: 50px;
        line-height: 50px;
        text-align: center;
        text-decoration: none;
        color: indigo;
        font-size: 18px;
        font-weight: 600;
      }
      .current{
          padding: 30px;
          font-size: 18px;
        font-weight: 600;
        color: gray;
          display: block;
          transition: all .3s;

      }
      .current>div{
          display: block;
        padding: 30px;
          font-size: 16px;
        
        color: gray;
      }
      .active{
          color: blue;
          
      }
    </style>
    <script src="./vue.js"></script>
  </head>
  <body>
    <div id="app">
      <div class="box">
        <div >
          <a href="#" @click.prevent='change(index)' :class="currentIndex==index?'active':''" :key='item.id'  v-for="(item,index) in arr" v-if='index<arr.length/2'>{{item.title}}</a>
        </div>
        <div class="content transition" :class="currentIndex==index?'current':''" :key='item.id' v-for='(item,index) in arr' >{{item.title}}<br>{{item.content}}</div>
        <div>
          <a href="#" @click.prevent='chang(index)' :class="currentIndex==index?'active':''" :key='item.id' v-for="(item,index) in arr" v-if='index>=arr.length/2'>{{item.title}}</a>
        </div>
      </div>
    </div>

    <script>
      let options = {
        el: "#app",
        data: {
        currentIndex:0,
          arr: [
            {
              id: 1,
              title: "SECTION 1",
              content: "content1",
            },
            {
              id: 2,
              title: "SECTION 2",
              content: "content2",
            },
            {
              id: 3,
              title: "SECTION 3",
              content: "content3",
            },

            {
              id: 4,
              title: "SECTION 4",
              content: "content4",
            },
            {
              id: 5,
              title: "SECTION 5",
              content: "content5",
            },
            {
              id: 6,
              title: "SECTION 6",
              content: "content6",
            },
          ],
        },
        methods: {
            change:function(index){
                this.currentIndex=index
            },
            chang:function(index){
              
                this.currentIndex=index
            }
        },
      };
      var vm = new Vue(options);
    </script>
  </body>
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值