我正在為學(xué)校做一個(gè) Laravel Vue 項(xiàng)目,我應(yīng)該通過(guò)從客戶(hù)端發(fā)送電子郵件來(lái)獲取用戶(hù),但是當(dāng)服務(wù)器響應(yīng)時(shí),我從響應(yīng)數(shù)據(jù)中得到一個(gè)空數(shù)組,而不是我想要從數(shù)據(jù)庫(kù)中獲取的數(shù)據(jù)。登錄.vuelogin() { this.showMessage = true; this.typeofmsg = "alert"; this.message = "Loggin in..."; axios.post('api/login', this.user) .then(response => { const token = response.data.access_token; this.$store.commit('setAccessToken', token); return axios.get('api/users/me', this.user.email); }) .then(response => { console.log(response); }) .catch(error => { console.log("Error = " + error.message); }); },路線/api.jsRoute::get('users/me', 'UserControllerAPI@myProfile');用戶(hù)控制器APIpublic function myProfile(Request $request){ $email = $request->email; $user = User::where('email', $email)->first(); return new UserResource($user);}如果我嘗試使用郵遞員獲取它,它可以工作在開(kāi)發(fā)工具控制臺(tái)中我得到了這個(gè)抱歉,如果我不清楚,或者它是錯(cuò)誤的,我從昨天開(kāi)始一直在嘗試解決這個(gè)問(wèn)題,這讓我發(fā)瘋了。任何幫助表示贊賞編輯:路線錯(cuò)誤,但我改變了它,我得到了相同的,沒(méi)有數(shù)據(jù)。我也更改了控制臺(tái)圖片
2 回答

絕地?zé)o雙
TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊
更改此行:
return axios.get('api/users/me', this.user.email);
至
return axios.get('api/users/me', { params: { email: this.user.email } });

jeck貓
TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊
你有 api/user/me 并且在路由中你有 /userS/me
所以我想您必須在其中一個(gè)位置刪除 S 或添加 S 。
所以嘗試改變路線
Route::get('users/me', 'UserControllerAPI@myProfile');
至
Route::get('/user/me', 'UserControllerAPI@myProfile');
- 2 回答
- 0 關(guān)注
- 138 瀏覽
添加回答
舉報(bào)
0/150
提交
取消