[英]Larave Vue post request return 500 internal server error
我剛剛進入laravel並且對vuejs一無所知,或者我有一個非常簡單的代碼試圖向服務器發送一個請求,服務器應該返回一個帶有用戶名的警報,這是我的代碼。
刀片.php
<button user-id="{{ $user->id }}"></button>
Vue 組件
<template>
<div>
<a href="#" class="btn btn-primary" onclick="action">Follow</a>
</div>
</template>
<script>
export default{
props: [userId],
mounted(){
console.log('Component mounted.')
},
methods:{
action(){
axious.post('/follow/' + this.userId)
.then( response => {
alter( response.data )
})
}
}
}
</script>
代碼
路線
Route::post('/follow/{user}', [ProfileController::class, 'store'];
配置文件控制器類
public function store(User $user){
return $user->username;
}
錯誤
app.js:285 POST http://localhost:8000/follow/2 500 (Internal Server Error)
dispatchXhrRequest @ app.js:285
xhrAdapter @ app.js:119
dispatchRequest @ app.js:765
Promise.then (async)
request @ app.js:542
Axios.<computed> @ app.js:567
wrap @ app.js:1131
followUser @ app.js:1924
invokeWithErrorHandling @ app.js:39512
invoker @ app.js:39837
original._wrapper @ app.js:45196
app.js:699 Uncaught (in promise) Error: Request failed with status code 500
at createError (app.js:699)
at settle (app.js:960)
at XMLHttpRequest.handleLoad (app.js:168)
我剛剛發現錯誤,我沒有在 ProfileController 類中導入類 User。
謝謝大家的快速回復。
下次當您處理 api 請求並出現這樣的錯誤時,只需切換到網絡點擊開發人員工具並跟蹤您的請求,然后單擊響應,您就可以找到整個異常跟蹤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.