gpt4 book ai didi

javascript - 未捕获的类型错误 : not a function when calling method from data in Vue

转载 作者:行者123 更新时间:2023-11-28 17:25:06 25 4
gpt4 key购买 nike

当我运行此命令时,出现错误:“Uncaught TypeError: this.thePerson is not a function”:

var myApp = new Vue({
el: "#app",
data: {
person: [this.thePerson()]
},
methods: {
thePerson: function() {
return {
personNickname: "Bob",
personOwes: 0,
paymentType: {
card: true,
cash: false
}
};
}
}
});

我不明白为什么!

附注我意识到这是看起来很奇怪的代码,但是我使用函数返回数组内容是有原因的......

最佳答案

数据转换为函数。

var myApp = new Vue({
el: "#app",
data: function() {
return {
person: [this.thePerson()]
}
},
methods: {
thePerson: function() {
return {
personNickname: "Bob",
personOwes: 0,
paymentType: {
card: true,
cash: false
}
};
}
}
});

关于javascript - 未捕获的类型错误 : not a function when calling method from data in Vue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51832811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com