1. 程式人生 > >vue實現tab切換功能精簡版

vue實現tab切換功能精簡版

clas none nbsp port () lin line emp click

<template>
  <div>
      <p class="tabs"  v-for="(list,index) in lists" 
      :class="index == cur ? ‘red‘:‘‘" 
      @click="cur = index">
        {{list.title}}
      </p>
      <div class="content" v-for="(list,index) in lists" :style="{display: index==cur ? ‘block‘:‘none‘}"
> {{list.name}} </div> </div> </template> <script> export default { data () { return { lists: [ { title: "切換1", name: "內容1111" }, { title: "切換2", name:
"內容2222" } ], cur: 0 } } } </script> <style scoped> .tabs { display: inline-block; margin-left:10px; } .red { color: red; } .content { padding: 5px; } </style>

vue實現tab切換功能精簡版