Javascript 如何打印发送表单的结果消息';使用Fetch和Aurelia获取数据
当我尝试在Aurelia中使用fetch发布表单数据并在同一网页上打印消息(如果成功,${resultMessage}),我收到一个错误“Unhandled rejection TypeError:无法将属性'resultMessage'设置为undefined”Javascript 如何打印发送表单的结果消息';使用Fetch和Aurelia获取数据,javascript,fetch,aurelia,Javascript,Fetch,Aurelia,当我尝试在Aurelia中使用fetch发布表单数据并在同一网页上打印消息(如果成功,${resultMessage}),我收到一个错误“Unhandled rejection TypeError:无法将属性'resultMessage'设置为undefined” this.resultMessage=“新增新书” 在函数上下文中,此是函数,而不是类。相反,请使用箭头函数表示法,如下所示: .then(data => { if(data.id) {
this.resultMessage=“新增新书”
在函数
上下文中,此
是函数,而不是类。相反,请使用箭头函数表示法,如下所示:
.then(data => {
if(data.id) {
console.log(JSON.stringify(data));
this.resultMessage = "New book added";
})
现在
这个
应该是类。这个
在函数
上下文中是函数,而不是类。相反,请使用箭头函数表示法,如下所示:
.then(data => {
if(data.id) {
console.log(JSON.stringify(data));
this.resultMessage = "New book added";
})
现在这个
应该是类
{
"id": "2",
"errors": []
}
.then(data => {
if(data.id) {
console.log(JSON.stringify(data));
this.resultMessage = "New book added";
})