首页 > 其他分享 >Vue中Tabs标签页的使用

Vue中Tabs标签页的使用

时间:2024-05-10 16:44:43浏览次数:10  
标签:key Vue center Tabs 标签 value tab 组件 tabObj

本案例的优点是给每个tab标签的标题设置了状态值,并给不同的状态值设置了不同的背景颜色。

效果:

代码:

1、父组件

<template>
  <el-container class="container">
    <el-tabs v-model="activeName" type="border-card" style="width: 100%; height: 100%">
      <el-tab-pane :label="'用户管理('+sinfoAuditStr+')'" name="0">
        <hello-world1 ref="hello-world1"></hello-world1>
      </el-tab-pane>
      <el-tab-pane :label="'配置管理('+sqAuditStr+')'" name="1">
        <hello-world2 ref="hello-world2"></hello-world2>
      </el-tab-pane>
      <el-tab-pane :label="'角色管理('+swAuditStr+')'" name="2">
        <hello-world3 ref="hello-world3"></hello-world3>
      </el-tab-pane>
    </el-tabs>
  </el-container>
</template>

<script>
import HelloWorld1 from "@/components/HelloWorld1.vue";
import HelloWorld2 from "@/components/HelloWorld2.vue";
import HelloWorld3 from "@/components/HelloWorld3.vue";
const calendarTypeOptions = [
  { key: 0, value: '未提交' },
  { key: 1, value: '提交待审核' },
  { key: 2, value: '审核中' },
  { key: 3, value: '驳回' },
  { key: 4, value: '通过' }
]
// 讲对象数组转成对象
const typeMap = calendarTypeOptions.reduce((acc, cur) => {
  acc[cur.key] = cur.value
  return acc
}, {})
export default {
  name: 'HomeView',
  components: {
    HelloWorld3,
    HelloWorld2,
    HelloWorld1
  },
  data() {
    return {
      activeName: '0',
      sinfoAuditStr: '',
      sqAuditStr: '',
      swAuditStr: '',
    }
  },
  created() {
    this.sinfoAuditStr = typeMap[1] // 提交待审核
    this.sqAuditStr = typeMap[4] // 通过
    this.swAuditStr = typeMap[2] // 审核中
    setTimeout(() => {
      this.changeTabsColor()
    }, 10)
  },
  methods:{
    changeTabsColor() {
      this.changeTabColor(1, 'tab-0')
      this.changeTabColor(4, 'tab-1')
      this.changeTabColor(2, 'tab-2')
    },
    changeTabColor(status, tabId) {
      const tabObj = document.getElementById(tabId)
      if (status === 3) {
        tabObj.style.backgroundColor = '#e19696'
      } else if (status === 0) {
        tabObj.style.backgroundColor = '#e1dca8'
      } else if (status === 1 || status === 2) {
        tabObj.style.backgroundColor = '#ddaee1'
      } else if (status === 4) {
        tabObj.style.backgroundColor = '#b6e1a0'
      } else {
        tabObj.style.backgroundColor = '#f5f7fa'
      }
    },
  }
}
</script>
<style scoped>
.container{
  width: 100%;
  height: 800px;
  display: flex;
  flex-direction: column;
  /*justify-content: center;*/
  align-items: center;
  background-color: #CAE1FF;
}
</style>

注意:每个tab标签都会有id,依次为tab-0,tab-1,tab-2

2、子组件

子组件HelloWorld1

<template>
  <div class="hello">
    <div style="color: blue">这是用户管理子组件HelloWorld1</div>
  </div>
</template>

<script>
let that
export default {
  name: 'HelloWorld1',
  methods:{
  }
}
</script>

<style scoped lang="less">
.hello{
  width: 100%;
  height: 600px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #CAE1FF;

}
</style>

子组件HelloWorld2

<template>
  <div class="hello">
    <div style="color: red">这是配置管理子组件HelloWorld2</div>
  </div>
</template>

<script>
let that
export default {
  name: 'HelloWorld2',
  methods:{

  }
}
</script>

<style scoped lang="less">
.hello{
  width: 100%;
  height: 600px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #CAE1FF;
}
</style>

子组件HelloWorld3

<template>
  <div class="hello">
    <div style="color: green">这是角色管理子组件HelloWorld3</div>
  </div>
</template>

<script>
let that
export default {
  name: 'HelloWorld3',
  methods:{
  }
}
</script>

<style scoped lang="less">
.hello{
  width: 100%;
  height: 600px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #CAE1FF;
}
</style>

 

标签:key,Vue,center,Tabs,标签,value,tab,组件,tabObj
From: https://www.cnblogs.com/zwh0910/p/18184741

相关文章

  • vue3 vite项目H5页面 ios13进入页面出现白屏问题
    项目中碰见IOS系统进入页面出现白屏问题,记录一下问题排查过程一、页面可能报错进入页面是白屏,页面的 vconsole 也没有显示,首先想到的是页面是不是有什么报错,然后查看了别的机型,都没有问题,定位到只有IOS13有问题,想着会不会是什么语法在IOS13不兼容(这个问题之前出现过一个......
  • vue3中vue页面向组件传值(组件的引入)
    1//vue页面的操作2//vue页面中引入组件;组件放入components文件夹中3importpensionfrom"@/components/CarWenShidu/echart.vue";4importpensionshidufrom"@/components/CarWenShidu/echartshidu.vue";56//向组件中传值handleMethod通过datecode......
  • vue3 页面 自适应 高度 分页固定
    <template><divclass="app_box"><divclass="app_box_title"ref="refTile"><el-form:inline="true":model="formInline"class="demo-form-inline"label-......
  • Vue的step步骤条的使用
    效果如下:代码:1、父组件<template><el-containerclass="container"><el-steps:active="active"finish-status="success"simplestyle="margin-top:20px;background-color:white;height:30px;width:34%"&g......
  • 黑马-Vue前端
    前言HTML:负责网页的结构(标签:form表单/table表格/a/div/span)CSS:负责网页的表现(样式:color/font/background/width/height)JavaScript:负责网页的行为(交互效果)创建一个文件夹输入cmd执行code.回车,打开VsCodeVue一款用于构建用户界面的渐进式的JavaScript框架......
  • vue学习--模板语法(五、选项卡案例)
    案例:<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><scriptsrc="https://cdn.j......
  • vue学习--模板语法(四、属性样式绑定&流程语句)
    目录3.5属性绑定1.Vue如何动态处理属性?2.v-model的底层实现原理分析3.6样式处理1.class样式处理2.style样式处理3.7分支循环结构1.分支结构2.v-if与v-show区别3.循环结构3.5属性绑定1.Vue如何动态处理属性?v-bind指令用法<av-bind:href='url'>跳转</a>缩写形式<a......
  • 关于vue2自己得到的陈果(不懂的知识点)
    ref引用相关的知识点:ref='ruleRef'this.$refs.ruleRef.resetFields()        只针对表单的重置this,$refs.ruleRef.validate(valid=>{    这里validate是进行一次检验,参数是一个回调函数,valid是一个布尔值,表示表单的检验是否通过if(!valid)......
  • vue-router单页面应用的多标签页使用问题
    正常的思维做多vue页面应用,我们的第一反应是配置多个入口点,多个vue应用,编译成多个HTML文件,由服务器来决定路由。这是正常的思维。但谁知道单页面应用也能做到类似的效果呢。单页面不过是服务器路由变成了客户端路由,但通过一些技巧,也能实现类似服务器多页面路由的效果。客户端路......
  • Vue入门到关门之Vue3学习
    一、常用API注意:本文项目均使用脚手架为Vite1、setup函数(1)介绍如果在项目中使用配置项API,那么写起来就和vue2的写法是一样的;但是如果在项目中写的是组合式API,那么组件中所用到的:数据、方法等等,均要配置在setup中。此外,setup()钩子也是在组件中使用组合式API的入口,通常只在......