【Vue】在Vue中使用substring截取字符串报错:“TypeError: Cannot read properties of undefined”

350 阅读1分钟

最近使用Vue写前端遇到需要对接口返回的数据进行截取的情况,使用JS的substring截取成功且前端可正确显示,但是打开控制台发现有大量报错:TypeError: Cannot read properties of undefined。 查阅资料发现,是因为没有对变量进行判空处理。解决方法如下: 添加v-if判断字符存在

image.png 特此记录,希望能帮到遇到同样问题的朋友们。