错误:未捕获(承诺)TypeError:无法读取属性 未定义错误行的“推送”:“ this.name [i] .push(arrayData [0]); “
我不明白,因为console.log(“ data is loading:” + arrayData [0]);之前的行正在工作!
关于异步吗?有人可以帮我吗?
这是我的代码:
data: {
name: []
},methods: {
LoadData: function() {
console.log("onload fundtion. \n");
fetch('http://localhost/store/skininfor.txt')
.then(response => response.text())
.then((data) => {
// console.log(data);
var textByLine = data.split("\n");
for (var i = 0; i < textByLine.length; i++) {
var arrayData = textByLine[i].split(",");
console.log("data is loaded:" + arrayData[0]);
if (arrayData[0] !== undefined) {
this.name[i].push(arrayData[0]);
}
}
});
},