【问题标题】:Method Illuminate\View\View::response does not exist方法 Illuminate\View\View::response 不存在
【发布时间】:2019-11-12 17:35:20
【问题描述】:

当我想从表中获取数据时出现错误。

我的控制器:

public function admin()
{
    $users = User::with('subs')->get();
    return view('admin')->response()->json([
        'users' => $users,
    ], 200);
}

我的 vue.js 脚本:

export default {
    data() {
        return {
            users: []
        }
    },

    methods: {
        showUsers() {
            axios.get('admin/routes').then(response => {
                this.users = response.data.users;
            });
        }
    },
    mounted() {
        this.showUsers();
    }
}

我的刀片 html 代码:

<tr v-for="user in users">
    <td>{{ user.id }}</td>
    <td>{{ user.name }}</td>
</tr>

方法 Illuminate\View\View::response 不存在。

当我想从表中获取数据时。

【问题讨论】:

  • 您的回复未设置。检查 admin/routes 是否是正确的 url 路径以及 Web 服务是否返回任何相关数据。

标签: laravel vue.js laravel-5 vuejs2


【解决方案1】:

您的代码中一切都很好,只发送响应,因为我们只想要数据库表的数据,不需要返回视图。

return response()->json([
    'users' => $users,
]);

【讨论】:

    【解决方案2】:

    您无需为此返回视图,因为您只需要 JSON 响应即可让 API 工作。

    return response()->json([
        'users' => $users,
    ]);
    

    【讨论】:

      猜你喜欢
      • 2020-08-11
      • 1970-01-01
      • 2014-11-18
      • 2016-09-23
      • 2015-04-04
      • 2014-12-19
      • 2014-04-20
      • 2016-07-13
      • 1970-01-01
      相关资源
      最近更新 更多