我是使用div实现tabs的切换功能,成功的实现了切换的效果。直接贴代码:
<template>
<div class="projrct" v-show="masShow">
<div class="projrct-title">
<div class="title">11111111</div>
<div class="close-imgs" @click="close">
<img src="@/assets/imgs/scheme/measures/close.png" alt="" />
</div>
</div>
<div class="container">
<div class="btn-group">
<div
class="btn"
@click="tab('Chosice')"
:class="{ btnactive: active == 'Chosice' }"
>
选择项目
</div>
<div
class="btn"
@click="tab('Add')"
:class="{ btnactive: active == 'Add' }"
>
新增项目
</div>
<div
class="btn"
@click="tab('Delete')"
:class="{ btnactive: active == 'Delete' }"
>
删除项目
</div>
</div>
<div :is="tabs" keep-alive class="commonStatistics"></div>
</div>
</div>
</template>
<script>
import Chosice from "./project/addProject.vue";
import Delete from "./project/addProject.vue";
import Add from "./project/addProject.vue";
export default {
components: { Chosice, Delete, Add },
data() {
return {
masShow: true,
tabs: "Add",
active: "Add",
};
},
//方法表示一个具体的操作,主要书写业务逻辑;
methods: {
close() {
this.masShow = false;
},
tab(e) {
this.active = e; //颜色
this.tabs = e; //点击事件传标签名
},
},
};
</script>
<style lang="scss" scoped>
.btnactive {
background: #2c89e5;
color: #fff;
}
.projrct {
position: absolute;
width: 812.5px;
height: 679.5px;
top: 150%;
left: 65%;
background: url("~@/assets/imgs/scheme/measures/basepup.png") center no-repeat;
background-size: 99%;
z-index: 9;
&-title {
display: flex;
position: absolute;
top: 4%;
left: 6%;
.title {
font-family: Roboto;
font-style: normal;
font-weight: normal;
font-size: 24px;
line-height: 28px;
color: #ffffff;
}
.close-imgs {
position: absolute;
width: 17px;
height: 17px;
top: 4px;
right: -740%;
}
}
.container {
position: absolute;
margin: 0px 16px 20px 16px;
margin-top: 15%;
.btn-group {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
margin-bottom: 16px;
margin-left: 32px;
}
.btn {
width: 116px;
height: 30px;
margin-right: 2px;
font-family: Roboto;
font-style: normal;
font-weight: normal;
font-size: 18px;
line-height: 30px;
// color: #2c89e5;
text-align: center;
margin-right: 20px;
opacity: 0.8;
cursor: pointer;
border: 1px solid rgba(44, 137, 229, 0.5);
}
.commonStatistics {
position: absolute;
width: 7.8rem;
height: 100%;
}
}
.project-bottom {
display: flex;
position: absolute;
width: 7.8rem;
top: 88.5%;
text-align: center;
flex-direction: row;
flex-wrap: nowrap;
justify-content: space-between;
align-content: center;
.progress {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: flex-start;
text-align: center;
margin-top: 14px;
margin-left: 77px;
.progress-span {
font-family: Roboto;
font-style: normal;
font-weight: normal;
font-size: 14px;
line-height: 16px;
margin-right: 20px;
color: #ffffff;
}
.progress-left {
width: 4px;
height: 4px;
background: #1c96f2;
margin-right: 4px;
margin-top: 6px;
}
.progress-right {
width: 4px;
height: 4px;
background: #1c96f2;
margin-left: -45px;
margin-top: 6px;
}
.progress-con {
width: 495px;
// background: #1C96F2;
}
.butt {
width: 90px;
height: 40px;
font-family: Roboto;
font-style: normal;
font-weight: normal;
font-size: 18px;
line-height: 40px;
color: #ffffff;
background: #2c89e5;
margin-top: -15px;
margin-left: 0.78rem;
}
}
}
}
</style>
实现结果: