Javascript 无法在Axios promise处理程序Vue Js中放入多条语句
我在我的Laravel项目中使用Vue Js,在那里我使用它进行POST调用。 但是,在处理承诺时,它工作正常。我有以下问题:Javascript 无法在Axios promise处理程序Vue Js中放入多条语句,javascript,laravel,vue.js,Javascript,Laravel,Vue.js,我在我的Laravel项目中使用Vue Js,在那里我使用它进行POST调用。 但是,在处理承诺时,它工作正常。我有以下问题: axios.post('/customer/update',this.customer) .then(response =>( //this.customer = response.data.customer //if this line is uncommented, the scripts falls over
axios.post('/customer/update',this.customer)
.then(response =>(
//this.customer = response.data.customer //if this line is uncommented, the scripts falls over
this.error.text = response.data.message
)).then(response =>(
this.error.show = true
)).then(response =>(
this.error.class = true
)).catch(err => {
console.log(err);
})
}
我必须将几个.then()链接在一起,以处理其中的每个单数语句。理想情况下,我想这样做:
axios.post('/customer/update',this.customer)
.then(response =>(
this.customer = response.data.customer
this.error.text = response.data.message
this.error.show = true
this.error.class = true
)).catch(err => {
console.log(err);
})
}
有什么想法吗?因为我根本不知道上面这些有什么问题。它应该能工作,但不能
我得到了错误
Uncaught SyntaxError: Unexpected token 'this'
哪个指向我创建的标签
created(){
this.greeting;
console.log(this.customer)
}
我猜你有打字错误,用括号代替花括号,应该如下所示
axios.post('/customer/update',this.customer)
。然后(响应=>{
this.customer=response.data.customer
this.error.text=response.data.message
this.error.show=true
this.error.class=true
})
.catch(错误=>{
控制台日志(err);
});