element ui 实现 分步表单

方法一:

<template>
  <div class="main-container">
    <el-card :body-style="{ padding: '20px' }" shadow="hover">
      <el-steps
        :active="activeStep"
        align-center
        finish-status="success"
        class="steps-wrapper"
      >
        <el-step title="企业信息" description="" />
        <el-step title="添加印章" />
        <el-step title="备案材料" />
        <el-step title="制作印章" />
      </el-steps>
    </el-card>
    <el-card :body-style="{ padding: '5px' }" shadow="hover" class="margin-top-xs">
      <div class="title text-center padding">
        <el-link type="primary" :underline="false" class="text-xxl" />
      </div>
      <Firm
        v-if="activeStep === 1"
        :firm-info="FirmInfo"
        :order-info="OrderInfo"
        @next-step="next"
      />
      <AddSeal
        v-if="activeStep === 2"
        :firm-info="FirmInfo"
        :order-info="OrderInfo"
        @next-step="nextTo"
        @pre-step="preTo"
      />

      <RecordMessage
        v-if="activeStep === 3"
        :firm-info="FirmInfo"
        :order-info="OrderInfo"
        @next-step="nextTo"
        @pre-step="preTo"
      />
      <MakeSeal
        v-if="activeStep === 4"
        :firm-info="FirmInfo"
        :order-info="OrderInfo"
        @pre-step="preTo"
      />
    </el-card>
  </div>
</template>

<script>
import Firm from './addSealStep/Firm.vue'
import AddSeal from './addSealStep/AddSeal/AddSeal'
import RecordMessage from './addSealStep/record-message.vue'
import MakeSeal from './addSealStep/makeSeal/make-seal.vue'
export default {
  name: 'Addseal',
  components: { Firm, AddSeal, RecordMessage, MakeSeal },
  data() {
    return {
      activeStep: 1,
      FirmInfo: {},
      OrderInfo: {},
      Id: ''
    }
  },
  watch: {
    activeStep(newVal, oldVal) {}
  },
  mounted() {
    if (this.$route.query.activeStep) {
      this.activeStep = Number(this.$route.query.activeStep)
    }
  },
  methods: {
    next(FirmInfo) {
      if (this.activeStep === 1) {
        this.FirmInfo = FirmInfo
        this.activeStep += 1
      }
    },
    nextTo(id) {
      this.activeStep += 1
      
    },
    preTo(id) {
      this.activeStep -= 1
      
    },
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-step__title {
  font-size: 14px;
}
@media screen and (max-width: 768px) {
  .steps-wrapper {
    width: 100%;
    margin: 0 auto;
  }
}
@media screen and (min-width: 768px) {
  .steps-wrapper {
    width: 100%;
    margin: 0 auto;
  }
}
</style>

方法二:

如何利用vue和Element-plus实现分步表单和表单校验-撸码网 (yingnd.com)

// StepperForm.vue
<template>
  <div class="stepper-form">
    <el-steps :active="activeStep" space="150px">
      <el-step title="基本信息"></el-step>
      <el-step title="联系方式"></el-step>
      <el-step title="其他信息"></el-step>
    </el-steps>
    <component :is="currentStep"></component>
    <div class="button-group">
      <el-button @click="prevStep" :disabled="activeStep === 0">上一步</el-button>
      <el-button @click="nextStep" :disabled="!validForm || activeStep === stepLength - 1">下一步</el-button>
    </div>
  </div>
</template>
<script>
import BasicInfoForm from './BasicInfoForm.vue'
import ContactForm from './ContactForm.vue'
import OtherForm from './OtherForm.vue'
export default {
  name: 'StepperForm',
  components: {
    BasicInfoForm,
    ContactForm,
    OtherForm
  },
  data() {
    return {
      activeStep: 0, // 当前处于哪个步骤
      stepLength: 3   // 总步骤数
    }
  },
  computed: {
    currentStep() {
      switch (this.activeStep) {
        case 0: return 'BasicInfoForm'
        case 1: return 'ContactForm'
        case 2: return 'OtherForm'
      }
    },
    validForm() {
      switch (this.activeStep) {
        case 0: return this.$refs.basicInfoForm.validate()
        case 1: return this.$refs.contactForm.validate()
        case 2: return this.$refs.otherForm.validate()
      }
    }
  },
  methods: {
    nextStep() {
      if (this.validForm) {
        this.activeStep += 1
      }
    },
    prevStep() {
      this.activeStep -= 1
    }
  }
}

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序媛刘刘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值