vue3 数据可视化大屏项目开发中,会需要一些tab切换组件,虽然已经有一些现成的组件了,这里整理的是 智慧园区可视化总控平台 导航组件。
使用实例
使用组件
/**
* @Author: 858834013@qq.com
* @Name: tab
* @Date: 2023年05月19日21:37:07
* @Desc: tab
*/
<template>
<div class="tabs">
<tab v-model:active="active" :list="navList"></tab>
</div>
</template>
<script>
import tab from './tab.vue'
import icon_taishi from './assets/icon_taishi.png'
import icon_anfang from './assets/icon_anfang.png'
import icon_shexiangtou from './assets/icon_shexiangtou.png'
import icon_zhaoshang from './assets/icon_zhaoshang.png'
import icon_nenghao from './assets/icon_nenghao.png'
export default {
name: "tabs",
components: {tab},
data() {
return {
active: '0',
navList: [{
name: '综合态势',
id: '0',
icon: icon_taishi,
}, {
name: '园区设施',
id: '1',
icon: icon_shexiangtou,
}, {
name: '招商监测',
id: '2',
icon: icon_zhaoshang,
}, {
name: '安防系统',
id: '3',
icon: icon_anfang,
}, {
name: '能耗管理',
id: '4',
icon: icon_nenghao,
}]
}
},
watch: {},
mounted() {
},
methods: {
getactive(e) {
this.$emit('update:active', e)
},
}
}
</script>
<style scoped lang="scss">
.tabs {
display: flex;
justify-content: flex-start;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
width: calc(100% - 40px);
margin: 10px auto;
.tab {
width: 116px;
height: 50px;
background: url("./assets/tabbg.png") center center no-repeat;
background-size: 116px 44px;
opacity: 1;
display: flex;
cursor: pointer;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
span {
font-size: 16px;
font-family: PingFang;
font-weight: 800;
color: #FFFFFF;
text-shadow: 0px 4px 10px rgba(22, 22, 20, 0.48);
background: linear-gradient(0deg, #ABC3E0 0%, #F2F9FF 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
}
.tab.active {
width: 116px;
height: 50px;
background: url("./assets/tabActiveBg.png") center center no-repeat;
background-size: 116px 50px;
opacity: 1;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
span {
font-size: 16px;
font-family: PingFang;
font-weight: 800;
color: #FFFFFF;
text-shadow: 0px 4px 10px rgba(22, 22, 20, 0.48);
background: linear-gradient(0deg, #0AD3D3 0%, #F2F9FF 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
}
}
</style>
组件代码
/**
* @Author: 858834013@qq.com
* @Name: tab
* @Date: 2023年05月19日21:37:13
* @Desc: tab
*/
<template>
<div class="tabs">
<div class="tab cur" :class="{active:active==item.id}" @click="getactive(item.id)" v-for="(item,index) in list"
:key="index">
<img :src="item.icon" alt="">
<span>{{ item.name }}</span>
</div>
</div>
</template>
<script>
export default {
name: "tabs",
components: {},
props: {
list: {
type: Array,
default() {
return [];
}
},
active: {
type: [Number, String],
default() {
return 0;
}
},
},
data() {
return {}
},
watch: {},
mounted() {
},
methods: {
getactive(e) {
this.$emit('update:active', e)
},
}
}
</script>
<style scoped lang="scss">
.tabs {
display: flex;
justify-content: flex-start;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
.tab {
width: 232px;
height: 65px;
background: url("./assets/menubg.png") center center no-repeat;
background-size: 232px 65px;
opacity: 1;
display: flex;
cursor: pointer;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
margin-left: -20px;
margin-right: -20px;
span {
font-size: 20px;
font-family: AppleSystemUIFont;
color: #D9F1FD;
}
img {
margin-right: 10px;
}
}
.tab.active {
width: 232px;
height: 65px;
background: url("./assets/meunbgActive.png") center center no-repeat;
background-size: 232px 65px;
opacity: 1;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
span {
font-size: 20px;
font-family: AppleSystemUIFont;
color: #FFFFFF;
}
}
}
</style>