【发布时间】: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。