vue步骤条组件

**子组件**
<template>
	<div class="steps-box">
	    <div
	      v-for="(item, index) in stepsData"
	      class="steps-card"
	      :class="index <= stepsIndex ? 'on' : ''"
	      :key="index">
	      <span>{{ index + 1 }}</span>
	      <span>{{ item.name }}</span>
	    </div>
	    </div>
	
</template>
``

```javascript
<script>
	export default {
	        data() {
	            return {
	                stepsIndex: "",
	                stepsData: [],
	            };
	        },
	        created() {
	            this.stepsIndex = this.$parent.stepsIndex;
	            this.stepsData = this.$parent.stepsData;
	        },
	        methods: {
	            //下一步
	            stepsFun() {
	                this.stepsIndex = this.$parent.stepsIndex;
	            }
	        },
	    };
</script>
<style lang="scss" scoped>
    /*    steps-box*/
    .steps-box {
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-bottom: 30px;
        margin-top: 200px;
        .steps-card {
            width: 300px;
            cursor: pointer;
            display: flex;
            align-items: center;
            color: rgba(0, 0, 0, 0.25);
            position: relative;
            span:nth-of-type(1) {
                display: inline-block;
                width: 26px;
                height: 26px;
                text-align: center;
                line-height: 26px;
                border: 1px solid rgba(0, 0, 0, 0.15);
                border-radius: 50%;
                margin-right: 10px;
 
                i {
                    font-style: normal;
                }
            }
        }
        .steps-card:before {
            width: 135px;
            height: 1px;
            content: "";
            background: #e9e9e9;
            margin: 0 15px;
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            right: 0;
        }
        .steps-card:last-of-type {
            width: auto;
        }
        .steps-card:last-of-type:before {
            width: 0;
        }
        .steps-card.on {
            display: flex;
            align-items: center;
            color: rgba(0, 0, 0, 0.85);
 
            span:nth-of-type(1) {
                display: inline-block;
                width: 26px;
                height: 26px;
                text-align: center;
                line-height: 26px;
                background: #1d73f6;
                border: 1px solid #1d73f6;
                color: #fff;
                border-radius: 50%;
                margin-right: 10px;
            }
        }
        .steps-card.on:before {
            background: #1d73f6;
        }
    }
</style>

**父组件调用组件**
<!-- 步骤条 -->
		<div class="addTask">
			<!--步骤条-->
			<steps ref="stepsChild"></steps>
			<!--内容区域-->
			<div class="task-main-box">
				<div v-if="stepsIndex == 0" class="task-con-box">
					<h1>第一步</h1>
				</div>
				<div v-if="stepsIndex == 1" class="task-con-box">
					<h1>第二步</h1>
				</div>
				<div v-if="stepsIndex == 2" class="task-con-box">
					<h1>第三步</h1>
				</div>
				<div v-if="stepsIndex == 3" class="task-con-box">
					<h1>第四步</h1>
				</div>
			</div>
			<!--操作按钮-->
			<div class="button-box">
				<div v-if="stepsIndex == 0">取消</div>
				<div v-if="stepsIndex == 3">完成</div>
				<div @click="prevSteps" v-if="stepsIndex != 0">上一步</div>
				<div @click="nextSteps" v-if="stepsIndex != 3">下一步</div>
			</div>
		</div>
<script>
import steps from "./step.vue";
export default {
		data() {
			return {
				stepsIndex: 0,
				stepsData: [{
						name: '第一步'
					},
					{
						name: '第二步'
					},
					{
						name: '第三步'
					},
					{
						name: '第四步'
					}
				]
			}
		}
		components: {
			steps,
		},
		methods: {
			//下一步
			prevSteps() {
			this.stepsIndex--
			this.$refs.stepsChild.stepsFun()
			},
			nextSteps() {
			this.stepsIndex++
			this.$refs.stepsChild.stepsFun()
			}
		}
		}
		
</script>
<style lang="scss" scoped>
	.addTask {
		width: 100%;
		height: 100%;
		overflow: hidden;

		.task-main-box {
			width: 100%;
			height: calc(100% - 45vh);

			.task-con-box {
				width: 100%;
				height: 100%;

			}
		}

		.button-box {
			display: flex;
			justify-content: center;

			div {
				padding: 10px;
				background: #2F86FF;
				margin: 10px;
				border-radius: 4px;
				cursor: pointer;
				color: #ffffff;
			}
		}

	}
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值