yusdddd_ 2022-04-14 01:28 采纳率: 94.1%
浏览 84
已结题

v-for里面的index怎么传给@click里面的方法?

问题遇到的现象和发生背景

想把v-for里面的index的值传给@click方法应该怎么样才可以?

有问题的那行在第20行后面的@click

问题相关代码,请勿粘贴截图
    <!-- 多选题模板 -->
  <div class="duoxuan main_workType" v-for="(item,index1) in moreChsObject" :key="index1">
    <div class="quesType" >{{index1+1}}.多选题</div>
    <el-input
      type="textarea"
      :autosize="{ minRows: 2, maxRows: 4}"
      placeholder="请输入题目内容"
      v-model="moreChs_text">
    </el-input>
    <div class="duoxuan-options"> 

      <!-- 选项 -->
        <div class="option" v-for="(item,index) in moreChsObject[index1].moreChsOptionsCount" :key="index">
          <el-button round class="duoxuan-chose">{{chsOptions[index]}}</el-button>
          <el-input v-model="weizhi" placeholder="请输选项A的内容" class="duoxuan-input"></el-input>
        </div>         
    
    </div>
    <div class="choose_Btn">
      <span class="addBtn"><el-button type="primary" icon="el-icon-plus" circle @click="moreChsOptionAdd(index1)"></el-button>增加选项</span>
      <span class="delBtn"><el-button type="danger" icon="el-icon-delete" circle @click="moreChsReduce"></el-button>删除选项</span>
    </div>
    <div class="duoChs-answer">
      <span class="duoChs-answer-text">请选择该题答案: </span>
        <el-checkbox-group v-model="checkboxGroup1" class="duoChs_ans">
          <el-checkbox-button v-for="city in cities" :label="city" :key="city">{{city}}</el-checkbox-button>
        </el-checkbox-group>
    </div>
  </div>

moreChsOptionAdd(index1){
  if(this.moreChsObject[index1].moreChsOptionCount<7){
    if(this.moreChsObject[index1].moreChsOptionCount=4){
      this.moreChsObject[index1].moreChsOptionCount+=1
      this.moreChsObject[index1].moreChsOption5 = "moreChs_options_5_"+index1
    }else if(this.moreChsObject[index1].moreChsOptionCount=5){
      this.moreChsObject[index1].moreChsOptionCount+=1
      this.moreChsObject[index1].moreChsOption6 = "moreChs_options_6_"+index1
    }else if(this.moreChsObject[index1].moreChsOptionCount=6){
      this.moreChsObject[index1].moreChsOptionCount+=1
      this.moreChsObject[index1].moreChsOption7 = "moreChs_options_7_"+index1
    }else this.$message.error("不可能走这里");
  }else{
    this.$message.error("不能大于7个选项");
    console.log(index1)
    console.log(this.moreChsObject[index1].moreChsOptionCount)
  }

},
运行结果及报错内容

这样子传的参数传进去变成了undefined

我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

1条回答 默认 最新

  • yusdddd_ 2022-04-14 02:11
    关注

    可以取,是我的方法写错了,终结终结!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月22日
  • 已采纳回答 4月14日
  • 修改了问题 4月14日
  • 创建了问题 4月14日

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号