vue tab选项卡

博客介绍了在实际项目中运用选项卡的实现方式。因业务中选项卡内容较多,采用父组件引入子组件的方式。新建父组件,可自行引入fund、bond等五个子组件。

选项卡在实际项目中还是会经常运用到的,非常简单,但也记录下。因业务上的选项卡内容还是比较多的,所以父组件引入子组件的方式来实现。
首先新建一个父组件,如下:

<template>
  <div class="service">
    <ul class="tab-list">
      <li
        v-for="(item ,index) in tabList"
        class="tab"
        :class="{active:active === index}"
        @click="toggle(index)"
      >{{item}}</li>
    </ul>
    <component :is="currentView" class="tab-main"></component>
  </div>
</template>

<script>
import fund from "@/views/service/fund";
import bond from "@/views/service/bond";
import trust from "@/views/service/trust";
import insure from "@/views/service/insure";
import beauty from "@/views/service/beauty";

export default {
  components: {
    fund,
    bond,
    trust,
    insure,
    beauty
  },
  data() {
    return {
      active: 0,
      currentView: "fund",
      tabList: ["私募基金","可转债","信托","保险","医美"]
    };
  },
  methods: {
    toggle: function(index) {
      this.active = index;
      if (index == 0) {
        this.currentView = "fund";
      } else if (index == 1) {
        this.currentView = "bond";
      } else if (index == 2) {
        this.currentView = "trust";
      } else if (index == 3) {
        this.currentView = "insure";
      } else if (index == 4) {
        this.currentView = "beauty";
      }
    }
  }
};
</script>
<style scoped lang="less" src="@/assets/css/service.less"></style>

fund,bond,trust,insure,beauty等五个是子组件,可自行引入。

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值