Vue动态选项卡

<style>
    button.active{
      background-color: rgb(235, 150, 53);
    }
    .content{
      width: 200px;
      height: 200px;
      line-height: 200px;
      text-align: center;
      font-size: 30px;
      border: 1px solid #333;
    }
  </style>
</head>
<body>
  <div id="app">
      <div>
          <button @click="switchTab(0)" :class="{active: activeIndex===0}">选项1</button>
          <button @click="switchTab(1)" :class="{active: activeIndex===1}">选项2</button>
          <button @click="switchTab(2)" :class="{active: activeIndex===2}">选项3</button>
          <div v-show="activeIndex===0" class="content">内容1</div>
          <div v-show="activeIndex===1" class="content">内容2</div>
          <div v-show="activeIndex===2" class="content">内容3</div>

      </div>
  </div>
  <script src="./vue.js"></script>
  <script>
    const vm = new Vue({
      el: '#app',
      data: {
        activeIndex: 0
      },
      methods: {
        switchTab(index){
          this.activeIndex = index;
        }
      }
    })
  </script>

 

posted @ 2021-12-01 14:35  今晚没吃饱  阅读(114)  评论(0)    收藏  举报