javascript - vueJS如何在不同选项卡显示不同内容

标签 javascript html vue.js tabs vuetify.js

我正在尝试使用 vueJS 框架和 vuetify 模板构建一个网站。我想在不同的选项卡下显示不同的内容。我写了一段代码,但是三个选项卡中都出现相同的内容。我该怎么做呢?我已在此处附上代码。

  <v-tabs
    centered
    color="deep-purple accent-1"
    slot="extension"
    slider-color="yellow"
    v-model="model"
  >
    <v-tab href="#tab-1">
    Solar Panels
   </v-tab>

   <v-tab href="#tab-2">
   CCTV Panels
  </v-tab>

  <v-tab href="#tab-3">
  LED Lights
 </v-tab>
 </v-tabs>

 <v-tabs-items>
   <v-tabs-content id="tab-1">
     <v-card flat>
       <v-card-text>This is the first tab</v-card-text>
     </v-card>
   </v-tabs-content>
   <v-tabs-content id="tab-2">
     <v-card flat>
       <v-card-text>This is the second tab</v-card-text>
     </v-card>
   </v-tabs-content>
   <v-tabs-content id="tab-3">
     <v-card flat>
       <v-card-text>This is the third tab</v-card-text>
     </v-card>
   </v-tabs-content>
 </v-tabs-items>

最佳答案

我以前也遇到过同样的问题。看看试试这个。

基本选项卡由一系列标题和与每个标题相关的相应内容组成。使用 for 循环创建选项卡来动态定义各个组件

<v-tabs
          fixed-tabs
          v-model="tab"
        >
          <v-tabs-slider color="amber darken-3"></v-tabs-slider>
          <v-tab
            v-for="(item, index) in items"
            :class="{active: currentTab === index}"
            @click="currentTab = index"
            :key="item"
          >
            {{ item }}
          </v-tab>
        </v-tabs>

       // Display different content here
        <v-tabs-items v-model="tab">
          <v-card flat>            
            <div v-show="currentTab === 0"><v-card-text>Tab0 content</v-card-text></div>
            <div v-show="currentTab === 1"><v-card-text>Tab1 content</v-card-text></div>
            <div v-show="currentTab === 2"><v-card-text>Tab2 content</v-card-text></div>
            <div v-show="currentTab === 3"><v-card-text>Tab3 content</v-card-text></div>
            <div v-show="currentTab === 4"><v-card-text>Tab4 content</v-card-text></div>
          </v-card>
        </v-tabs-items>
      </v-card>


export default {
   data () {
     return {
      currentTab: 0,
      tab: null,
      items: ['tab0', 'tab1', 'tab2', 'tab3', 'tab4'],
     }
  }

关于javascript - vueJS如何在不同选项卡显示不同内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49802899/

相关文章:

javascript - 更改 child 的 html

jquery - 在svg中查找圆圈内的元素

jquery - 无法将 API JSON 数据呈现到 vue js 中的表

html - vue.js 2 - 将单个文件组件的 html 片段提取到独立文件中

javascript - 关闭后取决于保持盒子

javascript - 在JS中打印镜像数字三 Angular 形

javascript - Fullcalendar 不在客户端呈现事件

javascript - 我可以在不使用 XMLHttpRequest 或文档对象的情况下使用 Javascript 获取网页吗?

javascript - 无法使用 javascript 更改 div 显示属性

vue.js - Vue中如何加载外部CSS