【问题标题】:Inertia JS consume laravel api惯性JS消耗laravel api
【发布时间】:2022-11-04 20:42:38
【问题描述】:

我知道惯性不需要 vue 路由器,但我有一个 Laravel API,我将从 vue 应用程序使用它并反应本机应用程序(移动),Web 端(vue 应用程序),我将它安装在 laravel 项目中,使用 Inertia .现在我想使用带有 json 响应的 Laravel 路由我不想渲染 Inertia 对象,但是 Link 组件在 backEnd 收到这样的惯性响应:
return Inertia::render('...')
当我返回 apiResponse 时:我收到此错误: All Inertia requests must receive a valid Inertia response, however a plain JSON response was received.

我知道这不是错误,但是有办法在前端使用 Inertia 并在后端使用 API 资源吗?或者我可以使用 vue-router 代替惯性路由器吗?

我的目标是让后端通用所有类型的前端应用程序。所以我必须返回 json 响应。

【问题讨论】:

  • 为什么不为移动设备创建单独的路线?

标签: laravel vue.js vue-router inertiajs


【解决方案1】:

如需返回 JSON 资源,请使用Axios

InertiaJS 用于构建单页应用程序,无需构建 API。

也就是说,Inertia 不用于构建 API。当您向 Inertia 发出请求时,它的响应是 Inertia 响应,并且不能是除该响应之外的其他类型的响应。点击here 了解它的工作原理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-10
    • 2021-08-23
    • 2022-11-11
    • 2021-06-02
    • 2022-01-18
    • 2021-01-23
    • 1970-01-01
    • 2022-10-14
    相关资源
    最近更新 更多