报错:cbsy:411 Uncaught TypeError: Cannot read properties of undefined (reading 'split')
at formatter (cbsy:411)
at Object.<anonymous> (echarts.min.js:6)
at Array.map (<anonymous>)
at Object.f [as map] (echarts.min.js:1)
at Object.s.<computed> [as getFormattedLabels] (echarts.min.js:6)
at a.n [as getFormattedLabels] (echarts.min.js:6)
at echarts.min.js:6
at r.getLabelInterval (echarts.min.js:6)
at e (echarts.min.js:6)
at a.render (echarts.min.js:6)
原因:
一开始看的还以为是函数调用错误还是不支持啥的,后来一想不可能,然后对数据进行了观察,val可能会存在空值的情况,也就是相当于java的空指针异常,在调用split()函数之前要对参数进行非空判断
源代码

解决方法:对调用方法的元素进行非空判断

在JavaScript编程中遇到一个常见的错误:`TypeError: Cannot read properties of undefined (reading 'split')`。该错误通常发生在尝试对未定义的变量执行`split()`方法时。博客内容指出,问题源于数据可能存在空值,导致在调用方法前没有进行非空检查。解决方法是在调用`split()`之前,确保变量已经被正确赋值且不为null或undefined。通过添加非空判断,可以避免这类运行时错误,提高代码的健壮性。
1万+

被折叠的 条评论
为什么被折叠?



