element-plus 报错 TypeError: Cannot read properties of undefined (reading ‘setCheckedKeys‘)

简介: element-plus 报错 TypeError: Cannot read properties of undefined (reading ‘setCheckedKeys‘)

报错

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'setCheckedKeys')

这个错误是因为你的dom元素还没有加载完,你就想使用 setCheckedKeys 设置目前勾选的节点。也就是你写的treeRef.value!.setCheckedKeys([3], false); 这个里面的 tree 还没有加载出来。

解决方案:

1、写进onMounted生命周期内

onMounted(async () => { 
 treeRef.value!.setCheckedKeys([3], false)
})

2、使用nextTick

import { nextTick  } from "vue";
nextTick(async () => {
 treeRef.value!.setCheckedKeys([3], false)
  })
目录
相关文章
|
5天前
webpack版本问题 Cannot read property ‘createHash‘ of undefined
webpack版本问题 Cannot read property ‘createHash‘ of undefined
|
6天前
|
iOS开发 MacOS
TypeError: Cannot read property ‘shop‘ of undefined
TypeError: Cannot read property ‘shop‘ of undefined
10 0
|
6天前
|
机器学习/深度学习
TypeError: Cannot read property ‘name‘ of undefined at Qe.onShow
TypeError: Cannot read property ‘name‘ of undefined at Qe.onShow
12 0
|
6天前
|
JavaScript
JS中Null和Undefined的区别及用法
JS中Null和Undefined的区别及用法
16 1
|
6天前
|
JavaScript 前端开发 算法
undefined与null的区别
在JavaScript中,undefined和null都表示变量未被赋值或值缺失,但它们在使用场景上有一些区别。 - **`语义不同`**:undefined表示一个变量未被赋值或者声明后未进行初始化。而null表示一个变量被明确地设置为无值或者表示空值的概念。 - **`类型不同`**:undefined是一种基本数据类型,而null是一个引用类型。 - **`条件判断`**:在条件判断中,使用if (variable === undefined)或者if (variable === null)可以进行区分。
|
6天前
|
JavaScript 前端开发 程序员
分享18个用于处理 null、NaN 和undefined 的 JS 代码片段
Null、NaN 和 undefined 是程序员在使用 JavaScript 时遇到的常见值。 有效处理这些值对于确保代码的稳定性和可靠性至关重要。
|
6天前
|
JavaScript 前端开发 API
null和undefined:两个JavaScript中的特殊值(二)
null和undefined:两个JavaScript中的特殊值
|
6天前
|
JavaScript 前端开发 安全
null和undefined:两个JavaScript中的特殊值(一)
null和undefined:两个JavaScript中的特殊值
|
8月前
【已解决】TypeError: Cannot destructure property `createHash` of ‘undefined‘ or ‘null‘
【已解决】TypeError: Cannot destructure property `createHash` of ‘undefined‘ or ‘null‘
207 1
|
6天前
|
前端开发 JavaScript
【Web 前端】undefined 和 null 区别?
【4月更文挑战第22天】【Web 前端】undefined 和 null 区别?
【Web 前端】undefined 和 null 区别?