代码之家  ›  专栏  ›  技术社区  ›  Ankit Verma

未捕获(承诺)类型错误:u webpack_imported_module_11_axios_uuu default(…)(…).Then(…).Then(…).Catch(…)不是函数

  •  -3
  • Ankit Verma  · 技术社区  · 7 年前
    axios({
                method: 'post',
                url: 'http://localhost:4000/login',
                data: {
                    user_email: formData.user_email.value,
                    user_password: formData.user_password.value,
                }
            })
                .then(res => res.json.then(user => ({ formData, res }))
                ).then(({ formdata, res }) =>  {
                if (!res.ok) {
                    // If there was a problem, we want to
                    // dispatch the error condition
                    dispatch(Error(formdata.message))
                    return Promise.reject(formdata)
                } else {
                    // If login was successful, set the token in local storage
                    localStorage.setItem('id_token', formdata.id_token)
                    localStorage.setItem('id_token', formdata.access_token)
                    // Dispatch the success action
                    // dispatch(formdata)
                }
            }).catch(err => console.log("Error: ", err))()
                .then(
                    (result) => {
                        this.setState({
                            isLoaded: true,
                            items: result.items
                        });
                    },
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Shubham Khatri    7 年前

    这个错误似乎给了你所有的信息。你有 () 在.catch块周围,它会警告您不能调用不是函数的东西。

     axios({
            method: 'post',
            url: 'http://localhost:4000/login',
            data: {
                user_email: formData.user_email.value,
                user_password: formData.user_password.value,
            }
        })
        .then(res => res.json().then(user => ({ formData, res })))
        .then(({ formdata, res }) =>  {
            if (!res.ok) {
                // If there was a problem, we want to
                // dispatch the error condition
                dispatch(Error(formdata.message))
                return Promise.reject(formdata)
            } else {
                // If login was successful, set the token in local storage
                localStorage.setItem('id_token', formdata.id_token)
                localStorage.setItem('id_token', formdata.access_token)
                // Dispatch the success action
                // dispatch(formdata)
                return Promise.resolve(res);
            }
        })
        .then((result) => {
              this.setState({
                   isLoaded: true,
                   items: result.items
              });
         })
        .catch(err => console.log("Error: ", err))
    

    另外,请在您的问题中添加一些关于您在问题中所面临的问题的相关信息,而不仅仅是将错误作为标题并提供代码。