【问题标题】:Network errors while updating through axios [duplicate]通过axios更新时出现网络错误[重复]
【发布时间】:2021-06-11 12:43:46
【问题描述】:

我想通过 vue axios 调用更新事件:

axios.put('/events/' + this.$route.params.id, this.form)
     .then(response => location.reload())

我的后端为此设置了路由:

Route::put('/events/{event}', [\App\Http\Controllers\EventController::class, 'update']);

当我提交表单时,它会在数据库中更新,但我也会在网络上遇到这样的错误,并且提交时页面不会重新加载:

{message: "The PUT method is not supported for this route. Supported methods: GET, HEAD, POST.",…}
//console errors
PUT http://localhost:8000/events 405 (Method Not Allowed)

我找不到解决此错误消息的方法

【问题讨论】:

  • 看起来this.$route.params.id 是一个空字符串。确保在发出请求时在路由中设置正确的 ID。

标签: laravel vue.js axios


【解决方案1】:

在前端使用结束行 '/'

axios.put('/events/' + this.$route.params.id + '/', this.form)
     .then(response => location.reload())

【讨论】:

  • 没有帮助。我不明白为什么会出现 PUT http://localhost:8000/events 405 (Method Not Allowed)
  • 在调用此 api 调用之前,您是否检查过控制台 this.$route.params.id
猜你喜欢
  • 2020-03-16
  • 2020-10-02
  • 1970-01-01
  • 2022-09-30
  • 2020-10-26
  • 2020-04-23
  • 2021-07-07
  • 2020-03-06
  • 1970-01-01
相关资源
最近更新 更多