为什么这里的三目运算符没办法成功走then里的代码呢,单独写POST或者PUT就可以,POST或者PUT里返回的是promise,axios的封装接口
const { bankName, cnapsNum, depositlBankName, id, status } = this.formData
const data = { bankName, cnapsNum, depositlBankName, id, status }
this.formData.id ? this.$commonPut('fund', 'fundbankinfo', data) : this.$commonPost('fund', 'fundbankinfo', data)
.then(res => {
console.log('res==========>', res)
if (res.code === 200) {
this.$message({
type: 'success',
message: '保存成功'
})
}
this.back()
})
.catch(error => console.log('error=====>', error))
let res = this.formData.id ? this.$commonPut('fund', 'fundbankinfo', data) : this.$commonPost('fund', 'fundbankinfo', data)
res.then(
async function a() {
const {bankName, cnapsNum, depositlBankName, id, status} = this.formData
const data = {bankName, cnapsNum, depositlBankName, id, status}
const res = this.formData.id ? await this.$commonPut('fund', 'fundbankinfo', data) : await this.$commonPost('fund', 'fundbankinfo', data)
console.log('res==========>', res)
if (res.code === 200) {
this.$message({
type: 'success',
message: '保存成功'
})
this.back()
} else {
console.log('error=====>', res)
}
}
可以换一种写法,你那种写法不行
res没有打印吗? network 接口 请求了吗? 还有就是 this.formData.id 要等于 false,或者 null,undefined时才会运行后面这个
this.$commonPut('fund', 'fundbankinfo', data) : this.$commonPost('fund', 'fundbankinfo', data)