959 Star 5.1K Fork 1.6K

GVPsmallwei / Avue

 / 详情

Crud中使用tree触发错误提示 annot read properties of null (reading 'key')

已完成
创建于  
2021-10-29 01:01

表单定义(CRUD)

{
    label: '上级机构',
    prop: 'orgId',
    type: 'tree',
    search: true,
    clearable: false,
    // dataType: 'string',
    dicUrl: '/api/blade-xxx/xxx/tree',
    props: {
      label: 'title',
      value: 'key'
    }
},

数据

[
  {
    "id": "32",
    "parentId": "0",
    "children": [
      {
        "id": "34",
        "parentId": "32",
        "children": [
          {
            "id": "42",
            "parentId": "34",
            "title": "三级公司",
            "key": "42",
            "value": "42"
          }
        ],
        "hasChildren": true,
        "title": "二级公司",
        "key": "34",
        "value": "34"
      }
    ],
    "hasChildren": true,
    "title": "总公司",
    "key": "32",
    "value": "32"
  }
]

在表单中,如果这个字段没有选择值(为空时,会触发以下错误)

error.js:21 TypeError: Cannot read properties of null (reading 'key')
    at $o (index.js:1)
    at e.getNode (index.js:1)
    at a.getNode (index.js:1)
    at a.<anonymous> (avue.min.js:formatted:11295)
    at Array.<anonymous> (vue.min.js:6)
    at qe (vue.min.js:6)

跟踪代码发现,在使用了tree作为组件时,进入页面会触发 init: function方法。

方法中,会去取一个默认节点值,但这个时候还没有选择数据,所以触发了该错误。。

AVUE 版本:2.8.18
element-ui版本:2.15.1

评论 (10)

jalena 创建了任务
smallwei 任务状态待办的 修改为进行中
展开全部操作日志

输入图片说明
输入图片说明

我这没复现啊 vue啥版本

不好意思,周末没上班。。

Vue版本是2.6.10

我这也是2.6.10。没复现

刚看了代码,这个标签上层有个group包裹

{
            label: '管理分类',
            prop: 'managerInfo',
            icon: 'el-icon-s-tools',
            column: [{
    label: '上级机构',
    prop: 'orgId',
    type: 'tree',
    search: true,
    clearable: false,
    // dataType: 'string',
    dicUrl: '/api/blade-xxx/xxx/tree',
    props: {
      label: 'title',
      value: 'key'
    }
}]
}

好的 我再试下

忘记说了哈,我是在编辑的时候出现的,不是新增的时候出现的哈

smallwei 任务状态进行中 修改为已完成
smallwei 任务状态已完成 修改为进行中

你的数据应该返回null导致,你返回“”试下

还真是哈!

应该是el的tree方法不支持null 报错了

632261 smallweigit 1588214431 smallwei 拥有者
回复 smallwei 拥有者

我下个版本优化下

smallwei 里程碑设置为v2.8.24
smallwei 任务状态进行中 修改为已完成

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
632261 smallweigit 1588214431 96103 jalena 1578917294
JavaScript
1
https://gitee.com/smallweigit/avue.git
git@gitee.com:smallweigit/avue.git
smallweigit
avue
Avue

搜索帮助

14c37bed 8189591 565d56ea 8189591