数字转字符串 爬坑—TypeError: Cannot read property ‘toString‘ of null

报错:Uncaught (in promise) TypeError: Cannot read property ‘toString’ of null
在这里插入图片描述
这里是需要把行政码由数字型转换成字符型,然后再遍历到表格中,但是遍历过程中,出现了此报错,最后发现,原来后端传来的行政码有些是空的,所以无法转换,继而就会把 toString() 报错
我最后把 toString()换成这样就j解决啦:

//原来是写成 province: this.list[i].provinceCode.toString()
province: this.list[i].provinceCode + '',  
city: this.list[i].cityCode + '',

你可能感兴趣的:(前端)