vue项目开发 pc页 tab切换样式模板,坚持记录模板样式和功能,将来可能都会用到,节省二次开发时间。
使用组件
<tab :active.sync="active" :list="statuslist"></tab>
data() {
return {
active: '0',
statuslist: [{
name: '最近7天',
id: '0'
}, {
name: '最近30天',
id: '1'
}]
}
},
模板代码
/**
* @Author: 858834013@qq.com
* @Name: tab
* @Date: 2022-07-24
* @Desc: vue pc 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"><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;
margin-left: 24px;
.tab {
width: 87px;
height: 31px;
background: rgba(#F5A523, 0);
border-radius: 4px 4px 4px 4px;
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: 14px;
font-family: Microsoft YaHei-Regular, Microsoft YaHei;
font-weight: 400;
color: #333333;
}
}
.tab.active {
width: 87px;
height: 31px;
background: #fef6e9;
border-radius: 4px 4px 4px 4px;
opacity: 1;
display: flex;
justify-content: center;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
span {
font-size: 14px;
font-family: Microsoft YaHei-Regular, Microsoft YaHei;
font-weight: 400;
color: #F5A523;
}
}
}
</style>