el-carousel更新时,当前页总会跑到最后一页

文章描述了一个关于前端页面中el-carousel组件在保存后总是跳转到最后一页的bug。后端发现这个问题并提供了详细的情景,涉及到的代码部分包括carousel的事件绑定和数据更新。解决方案可能集中在正确设置和同步carousel的当前索引与表单数据上。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

后端向前端提的bug

  • 当前页保存后,总会跑到最后一页去,
    在这里插入图片描述

获取当前索引

<el-carousel :autoplay='false' indicator-position='outside' trigger="click" arrow="always" @change="updateIndex">
      <el-carousel-item v-for="(form, index) in formList" :key="index">
      </el-carousel-item>
    </el-carousel>
    data(){
       currentIndex: 0,
    }
     updateIndex(num) {
      this.currentIndex = num;
      this.init()
    },

将表单索引值==el-carousel当前索引值

  async init() {
      const { data } = await GetFormData({ taskId: this.conditions.remark01, formName: this.formTableName })
      // 如果没有数据就清空form,重新加载
      if (data.data.length == 0) {
        this.getFrom()
        this.formList = []
        this.flag = true
        this.formList.push(this.form)
        return false
      }
      if (data.statusCode == 200) {
        this.flag = false
        // 获取到当前的表单
        data.data.forEach((el, index) => {
          if (this.currentIndex == index) {
            this.form = el.value
            this.form.id = el.id
          }
        })
           // 生成新的列表
          const values = data.data.map(item => item.value)
          this.formList = values
          console.log(  this.form ,"  this.form ");
          console.log("formList",this.formList);
      }

    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值