el-cascader的getCheckedNodes获取值为空

描述:在表格中动态插入行时,每行中的el-cascader触发change事件时获取节点getCheckedNodes为空,原以为是dom节点未及时更新,使用$nextTick可解决问题,但发现并未起作用

表格添加多条时el-cascader的change事件只有最后条getCheckedNodes能获取到数据,想到用this. r e f s [ " c a s c a d e r " ] [ i n d e x ] . g e t C h e c k e d N o d e s ( ) 去 解 决 , 可 是 发 现 t h i s . refs["cascader"][index].getCheckedNodes()去解决,可是发现this. refs["cascader"][index].getCheckedNodes()this.refs[“cascader”]并不是一个数组,最后想到一个解决方案,动态生成ref,虽然不是很好,但能解决问题了

el-cascader的getCheckedNodes获取值为空_第1张图片

 <el-table-column label="指标值" align="center" prop="gradeValue">
                <template slot-scope="scope">
                  <el-form-item :key="scope.$index" :prop="'gradeWeightReqModelList.'+scope.$index+'.gradeValue'" :rules="{ required: true, message: '指标值不能为空', trigger: 'blur' }" label-width="0" style="margin:18px 0;">
                    <el-input v-model="scope.row.gradeValue" :change="checkNumber(scope.row.gradeValue,scope.$index,'1',scope.row)" :placeholder="scope.row.gradeDesc" clearable size="small" type="text" :maxlength="scope.row.gradeDesc=='字母'?1:999" />
                  </el-form-item>
                </template>
              </el-table-column>```

![在这里插入图片描述](https://img-blog.csdnimg.cn/d8955ad1b3bb46f69bbe062a8d2ccd49.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5q2j5Zyo5YmN6KGM55qE5bCP56CB5Yac,size_20,color_FFFFFF,t_70,g_se,x_16)

```javascript
    // 指标枚举值change事件
    handleChange(val, index, row) {
      let res = 'cascader' + index
      let node = this.$refs[res].getCheckedNodes()[0]
      this.formData.gradeWeightReqModelList[index].gradeName = node.label
      this.formData.gradeWeightReqModelList[index].gradeId = row.gradeId
      this.formData.gradeWeightReqModelList[index].gradeDesc = this.handleUnit(node.data.dictPattern)
    },```

你可能感兴趣的:(vue,elementui)