其实这个功能本身js方法不难,我花时间是在布局上。
<template>
<div class="box-wrap">
<div class="wrap">
<div class="box" v-for="item in this.stepList" :key="item.id">
<div class="heng icon">
<div v-if="!item.done" class="heng numflag">{{item.id}}</div>
<div v-else class="heng iconflag"></div>
</div>
<div class="tag-title">
{{item.title}}
<div class="border-zore" v-if="item.id !== stepList.length" :class="item.done ? 'active' : ''"></div>
</div>
</div>
</div>
<!-- 每个部分具体操作 -->
<div class="tag-descript"></div>
<button @click="onDone()">完成</button>
</div>
</template>
<script>
export default {
data() {
return {
stepList: [
{
id: 1,
title: '填写基本信息',
done: false,
descript: "第一部分信息"
},
{
id: 2,
title: '设置密码',
done: false,
descript: "第二部分信息"
},
{
id: 3,
title: '确认信息',
done: false,
descript: "第三部分信息"
},
],
doneNum: 0,
}
},
methods: {
onDone() {
let stepList = this.stepList
if(this.doneNum <= stepList.length) {
this.doneNum += 1
stepList.map(item=>{
if(this.doneNum === item.id) {
item.title = '已完成'
item.done = true
}
})
} else {
this.doneNum = 0
}
}
}
}
</script>
在写样式的时候,
display:inline;设置的宽度失效,定位失效。(需注意使用)
<style scoped>
.box-wrap {
width: 76%;
margin: 0 auto;
background-color: #d8d1d231;
}
.wrap {
width: 100%;
display: flex;
justify-content: flex-start;
padding: 10px;
}
.box {
width: 33%;
display: flex;
justify-content: start;
}
.heng {
display: inline;
}
.icon {
width: 30px;
height: 30px;
}
.numflag {
width: 100%;
height: 100%;
font-size: 18px;
color: #fff;
padding: 2px 8px;
box-sizing: border-box;
background-color: #c5c8ce;
border-radius: 50%;
}
.iconflag::before {
content: '√';
width: 25px;
height: 25px;
line-height: 25px;
text-align: center;
font-size: 18px;
color: #2d8cf0;
border: 1px solid #2d8cf0;
border-radius: 50%;
padding: 2px 6px;
}
.tag-title {
position: relative;
width: 100%;
margin-left: 14px;
height: 30px;
font-size: 18px;
letter-spacing: 2px;
padding-right: 200px;
box-sizing: border-box;
}
.border-zore {
width: 50%;
height: 2px;
background-color: #c5c8ce;
position: absolute;
top: 12px;
left: 36%;
}
.active {
background-color: #2d8cf0;
}
.tag-descript {
margin-top: 20px;
}
</style>