vue a标签新建页跳转_vue标签页(Tabs)最佳实践

bb853b64064a34bb589d9d37d38b9390.png

vue中Tabs的各种花式写法,官网也没有也给最佳实践。在实时性比较高的一些系统中,组件切换时可能数据已经更新了,这时候就需要组件动态载入。

<template>
  <div class="container">
    <el-tabs v-model="active">
      <el-tab-pane
        v-for="item in tabs"
        :key="item.id"
        :label="item.title"
      >
        <component
            v-bind:is="active === item.id ? item.component : false"
          ></component>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script type="text/ecmascript-6">
export default {
  name: 'demo',
  components: {},
  props: {},
  data () {
    return {
      active : 0,
      tabs: [{
          title: '标签a',
          id: 0,
          component: () => import('./components/a')
        }, {
          title: '标签b',
          id: 1,
          component: () => import('./components/b')
      }, {
          title: '标签c',
          id: 2,
          component: () => import('./components/c')
      }, {
        title: '标签d',
        id: 3,
        component: () => import('./components/d')
      }]
    }
  }
}
</script>

写 Vue一个多月了,相比React,vue很多功能的实现都非常简单,开发速度高效。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue中实现Tabs标签可以通过以下步骤: 1. 在Vue组件中定义一个data属性,用于保存Tabs的数据,如选中的标签标签内容等。 ``` data () { return { activeTab: 0, tabs: [ { label: 'Tab 1', content: 'Content of Tab 1' }, { label: 'Tab 2', content: 'Content of Tab 2' }, { label: 'Tab 3', content: 'Content of Tab 3' }, ] } } ``` 2. 在模板中使用v-for指令,遍历tabs数组,生成标签并绑定事件。 ``` <ul class="tabs"> <li v-for="(tab, index) in tabs" :key="index" :class="{ active: activeTab === index }" @click="activeTab = index"> {{ tab.label }} </li> </ul> ``` 3. 在模板中使用v-show指令,根据选中的标签,显示对应的标签内容。 ``` <div class="tab-content" v-for="(tab, index) in tabs" :key="index" v-show="activeTab === index"> {{ tab.content }} </div> ``` 最终的代码如下: ``` <template> <div class="tabs-container"> <ul class="tabs"> <li v-for="(tab, index) in tabs" :key="index" :class="{ active: activeTab === index }" @click="activeTab = index"> {{ tab.label }} </li> </ul> <div class="tab-content" v-for="(tab, index) in tabs" :key="index" v-show="activeTab === index"> {{ tab.content }} </div> </div> </template> <script> export default { data () { return { activeTab: 0, tabs: [ { label: 'Tab 1', content: 'Content of Tab 1' }, { label: 'Tab 2', content: 'Content of Tab 2' }, { label: 'Tab 3', content: 'Content of Tab 3' }, ] } } } </script> <style> .tabs-container { display: flex; flex-direction: column; border: 1px solid #ccc; border-radius: 5px; overflow: hidden; } .tabs { display: flex; justify-content: space-between; list-style-type: none; margin: 0; padding: 0; background-color: #f2f2f2; } .tabs li { flex-grow: 1; text-align: center; padding: 10px; cursor: pointer; border-bottom: 1px solid #ccc; } .tabs li.active { background-color: #fff; border-bottom: none; } .tab-content { padding: 20px; } </style> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值