Reactjs 在sweetalert2中显示来自预确认的错误消息
Im使用Reactjs 在sweetalert2中显示来自预确认的错误消息,reactjs,sweetalert2,Reactjs,Sweetalert2,Im使用sweetalert2和sweetalert2反应内容。我的inputValidator工作正常,它会向用户显示错误。在我有AJAX请求的预确认中,我如何做同样的事情 MySwal.fire({ title: 'title', input: 'text', html: this.renderInfoText(), showLoaderOnConfirm: true, inputValidator: (
sweetalert2
和sweetalert2反应内容
。我的inputValidator
工作正常,它会向用户显示错误。在我有AJAX请求的预确认
中,我如何做同样的事情
MySwal.fire({
title: 'title',
input: 'text',
html: this.renderInfoText(),
showLoaderOnConfirm: true,
inputValidator: (value) => {
return new Promise((resolve) => {
if (this.validate(value)) {
resolve()
} else {
resolve('check formatting...')
}
})
},
preConfirm: (pno) => {
return axios.post('/some/route', { pno })
.then(response => {
// ...
})
.catch(error => {
// show an error message to the user from here?
});
}
})
他们正在使用fetch,请尝试使用它
MySwal.fire({
title: 'title',
input: 'text',
html: this.renderInfoText(),
showLoaderOnConfirm: true,
inputValidator: (value) => {
return new Promise((resolve) => {
if (this.validate(value)) {
resolve()
} else {
resolve('check formatting...')
}
})
},
preConfirm: (pno) => {
return fetch('/some/route', {
method: 'POST',
body: JSON.stringify(pno),
headers: {
'Content-Type': 'application/json'
})
.then(response => {
// ...
})
.catch(error => {
// show an error message to the user from here?
});
}
})
这实际上记录在
AJAX请求示例下的中。以下是我的解决方案:
MySwal.fire({
title: 'title',
input: 'text',
html: this.renderInfoText(),
showLoaderOnConfirm: true,
inputValidator: (value) => {
return new Promise((resolve) => {
if (this.validate(value)) {
resolve()
} else {
resolve('check formatting...')
}
})
},
preConfirm: (pno) => {
return axios.post('/some/route', { pno })
.then(response => {
// ...
})
.catch(error => {
if (error.response.status === 404) {
MySwal.showValidationMessage(error.response.data.message)
}
});
}
})
尝试使用fetch而不是axios,我已经快速浏览了网站,他们正在使用fetch。感谢您的努力,在文档中找到了解决方案。解锁后我会给你赏金。