Vue多个按钮切换不同子页面

前言

在开发中难免碰到这样的页面,一个页面展示许多可以点击的按钮,点击不同按钮对应本页面的子页面切换不同的子页面。相信对于这种页面大家并不少见,而碰到这种情况的时候,都需要一个模板,节省开发时间!

先看效果

在这里插入图片描述

再给代码

<template>
  <div>
    <div style="width: 100%; height: 8vh;">
      <el-button-group>
        <el-button
          v-for="(page, index) in pages"
          :key="index"
          size="small"
          :class="{ 'is-active': activeIndex === index }"
          @click="changePage(index)"
          style="margin-left: 4vw;margin-top: 2vh;border-radius: 5px;"
          >
          {{ page.buttonText }}
        </el-button>
      </el-button-group>
    </div>

    <div v-for="(page, index) in pages" :key="index" v-show="activeIndex === index">
      <component :is="page.component"></component>
    </div>

  </div>
</template>



<script>

export default {
  data() {
    return {
      title: "**",
      pages: [
        { buttonText: '按钮名称', component: tqld },
        { buttonText: '按钮名称', component: fkxld },
        { buttonText: '按钮名称', component: gkqxgc },
        { buttonText: '按钮名称', component: dmqxgc },
        { buttonText: '按钮名称', component: gnssmetgc },
        { buttonText: '按钮名称', component: zdtrsfgc },
        { buttonText: '按钮名称', component: ldgc },
        // 可根据需要添加更多页面,component是引入的vue子页面
      ],
      activeIndex: 0,
    };
 },

methods: {
    changePage(index) {
      this.activeIndex = index;
    },
  }
}
</script>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值