问题遇到的现象和发生背景
想把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