Reactjs 在sweetalert2中显示来自预确认的错误消息

Reactjs 在sweetalert2中显示来自预确认的错误消息,reactjs,sweetalert2,Reactjs,Sweetalert2,Im使用sweetalert2和sweetalert2反应内容。我的inputValidator工作正常,它会向用户显示错误。在我有AJAX请求的预确认中,我如何做同样的事情 MySwal.fire({ title: 'title', input: 'text', html: this.renderInfoText(), showLoaderOnConfirm: true, inputValidator: (

Im使用
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。感谢您的努力,在文档中找到了解决方案。解锁后我会给你赏金。