阅读 102

Error in render: "TypeError: Cannot read property 'length' of undefined

刚刚在用Element-UI写vue的一个功能的时候,遇到了一个问题,排查了一会儿,才找到原因,记录一下

页面的代码如下

<el-checkbox-group v-model="form.roleIds">
    <el-checkbox v-for="item in roleList" v-bind:key="item.id" :label="item.id">{{item.name}}</el-checkbox>
</el-checkbox-group>
复制代码

运行报错如下

vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in render: "TypeError: Cannot read property 'length' of undefined"

found in

---> <ElCheckbox> at packages/checkbox/src/checkbox.vue
       <ElCheckboxGroup> at packages/checkbox/src/checkbox-group.vue
         <ElFormItem> at packages/form/src/form-item.vue
           <ElCol>
             <ElRow>
               <ElForm> at packages/form/src/form.vue
                 <ElDialog> at packages/dialog/src/component.vue
                   <UserEdit> at src/views/common/authority/user-edit.vue
                     <SystemRole> at src/views/common/authority/user.vue
                       <EleEmptyLayout> at node_modules/ele-admin/packages/ele-empty-layout/src/main.vue... (1 recursive calls)
                         <EleProLayout> at node_modules/ele-admin/packages/ele-pro-layout/src/main.vue
                           <EleLayout> at src/layout/index.vue
                             <App> at src/App.vue
                               <Root>
复制代码

报错原因 v-model="form.roleIds" 中的 roleIds 没有在form中默认为数组,所以报错了

文章分类
前端
文章标签