在使用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字段并给类型为数组