iAm*_*oot 5 laravel vue.js laravel-5 vuejs2
当我想从表中获取数据时出现错误。
我的控制器:
public function admin()
{
$users = User::with('subs')->get();
return view('admin')->response()->json([
'users' => $users,
], 200);
}
Run Code Online (Sandbox Code Playgroud)
我的 vue.js 脚本:
export default {
data() {
return {
users: []
}
},
methods: {
showUsers() {
axios.get('admin/routes').then(response => {
this.users = response.data.users;
});
}
},
mounted() {
this.showUsers();
}
}
Run Code Online (Sandbox Code Playgroud)
我的刀片html代码:
<tr v-for="user in users">
<td>{{ user.id }}</td>
<td>{{ user.name }}</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
方法 Illuminate\View\View::response 不存在。
当我想从表中获取数据时。
小智 1
您不需要为此返回视图,因为您只需要 JSON 响应即可使 API 正常工作。
return response()->json([
'users' => $users,
]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10984 次 |
| 最近记录: |