今天写Vue项目时,遇到一个报错:TypeError: Cannot read properties of undefined (reading ‘split’). split报错?? 想起来有用到split切割后台返回来的字符串"1920X1080_60P". 但这个值吧,不一定每次都有,有时可能是空. 后经测试发现. 这个值为空的时候就报错. 没办法啊,做个判断吧,如果该值存在的时候,再进行操作赋值等.

 if (data.subresolution) {
                this.VideoFormat = data.subresolution.split("_")[0]; // 子设备分辨率
              }

这样就OK啦!

Logo

前往低代码交流专区

更多推荐