【发布时间】:2021-09-27 17:12:28
【问题描述】:
我从 Laravel 发送了一个 array,但在前端我收到了一个 object,不知道为什么。 也许我做错了什么。
//BACKEND
public function index($course_id){
$courses = CourseTopic::select([
'course_topics.id',
'course_topics.name',
])
->where('course_id', $course_id)
->get()
->groupBy('id')
->toArray();
foreach ($courses as $course_topic) {
// here I have some logic..
}
dd(gettype($courses)); -> here is Array
return response($courses);
}
//FRONTEND
getCourseAreas(){
this.$http.get('/course-area/' + this.course_id)
.then(res=>{
console.log(typeof res.data); -> here is Object
this.course_areas = res.data;
})
},
【问题讨论】:
-
试试
response()->json($courses),也可以试试typeof array is object