【发布时间】:2019-09-15 17:51:25
【问题描述】:
我有以下 get 请求,它在 mounted() 上执行。 当我明确地从 database 请求一些数据时,我以一些奇怪而神秘的方式返回我的主视图 app.blade 作为响应。
有人能看出我搞砸了什么吗?
我在前端的get request:
mounted() {
this.getProjectRequests();
},
methods: {
getProjectRequests: function() {
var self = this;
let clientId = this.$route.path.substring(
this.$route.path.lastIndexOf("/") + 1
);
axios({
method: "get",
url: "/get-project-requests/" + clientId
})
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log(error);
// TODO error handling
});
}
}
我的路线:
Route::get('/get-project-requests/{client_id}',
'SinglePageController@getProjectRequests');
还有我的控制器方法:
public function getProjectRequests($clientId) {
try {
$projectRequests = ProjectRequest::where('client_id',
$clientId)->value('name');
return response()->json( [
'success'=> true,
'projectRequests' => $projectRequests
]);
} catch(\Exception $e){
return ['success' => false, 'message' => 'getting
project requests failed'];
}
}
【问题讨论】: