elementUI checkBox报错Cannot read property 'length' of undefined解决
在使用el-checkbox时遇上这样的错误
TypeError: Cannot read property 'length' of undefined
at VueComponent.isLimitDisabled (element-ui.common.js?ccbf:6452)
at Watcher.get (vue.esm.js?efeb:4482)
at Watcher.evaluate (vue.esm.js?efeb:4587)
at VueComponent.computedGetter [as isLimitDisabled] (vue.esm.js?efeb:4839)
at VueComponent.isDisabled (element-ui.common.js?ccbf:6455)
at Watcher.get (vue.esm.js?efeb:4482)
at Watcher.evaluate (vue.esm.js?efeb:4587)
at VueComponent.computedGetter [as isDisabled] (vue.esm.js?efeb:4839)
at Object.get (vue.esm.js?efeb:2104)
at Proxy.checkboxvue_type_template_id_d0387074_render (element-ui.common.js?ccbf:6161)
在template中,我的这样绑定的:
<!-- 多选 -->
<template>
<el-checkbox-group v-model="examData[current].answer">
<el-checkbox
:label="item"
v-for="(item, index) in examData[current].tmDa"
@change="examData[current].complete = true">
<strong>{{String.fromCharCode('A'.charCodeAt(0) + index)}}</strong>
<span>{{item}}</span>
</el-checkbox>
</el-checkbox-group>
</template>在data选项中:
data() {
return {
examData: [
{
answer: [],
title: '问题,问题,问题?',
options: [
'答案1',
'答案2',
'答案3',
'答案4',
],
complete: false,
},
]
}
}
报错的原因:
在data中其实是我们的静态数据,从后端拿到的数据赋值给examData,发现examData里少了answer 的字段
我们必须给数据添加answer字段并给类型为数组
以上就是elementUI checkBox报错Cannot read property ‘length‘ of undefined解决的详细内容,更多关于elementUI checkBox报错的资料请关注脚本之家其它相关文章!
相关文章
Vue中的三种Props:模板Props、配置Props和状态Props详解
这篇文章介绍了Vue中的Props,主要有三种类型:模板Props、配置Props和状态Props,模板Props用于简单的数据传递和显示,配置Props用于调整组件的行为和外观,状态Props用于管理组件内部的动态数据,每种类型都有其应用场景,理解这些类型可以帮助你设计出更棒的组件2025-02-02
element-ui table表格控件实现单选功能代码实例
这篇文章主要给大家介绍了关于element-ui table表格控件实现单选功能的相关资料,单选框是指在 Element UI 的表格组件中,可以通过单选框来选择一行数据。用户只能选择一行数据,而不能同时选择多行,需要的朋友可以参考下2023-09-09


最新评论