【问题标题】:erorr api post vue laravel错误api发布vue laravel
【发布时间】:2021-10-05 06:37:40
【问题描述】:

这是我的代码

async inputschedule(){
        await axios.post('api/schedule',{
                tweet:this.text,
                schedule_at:this.data+' '+this.clock
        })
        .then((response)=>{
             if (response.status == 400){
                 console.log(response.status)
                 this.error='Il post non può essere pianificato per questa data'
             }
             
            
        })
        },

即使状态为 400 变量错误未填充,我错了什么?

【问题讨论】:

    标签: laravel vue.js


    【解决方案1】:

    你是对的。每当axios 实例收到状态码超出 2xx 范围的响应时,它都会抛出错误。 Reference

    您可以使用以下代码实现您的功能。

    async inputschedule(){
      await axios.post('api/schedule',{
        tweet:this.text,
        schedule_at:this.data+' '+this.clock
      })
      .then((response) => {
        // Handle success response.
      }
      .catch((error)=>{
        // Check whether the response was received.
        if (error.response) {
          if (error.response.status == 400){
            console.log(error.response.status)
            this.error='Il post non può essere pianificato per questa data'
          }
        }
      })
    },
    

    【讨论】:

    • 不起作用:(
    • 什么不完全有效?你能分享你收到的错误吗?
    • 您可以尝试删除await 关键字吗?
    • 我没有收到任何错误,但没有填充错误变量
    • 您是否看到正在记录到控制台的状态代码?
    猜你喜欢
    • 2017-07-25
    • 2019-10-21
    • 2018-10-16
    • 2021-01-14
    • 2016-03-04
    • 2017-10-20
    • 2023-03-13
    • 1970-01-01
    • 2015-06-19
    相关资源
    最近更新 更多