【发布时间】:2021-09-03 10:30:16
【问题描述】:
刚接触 Inertia 时遇到了一些麻烦:
我在 Vue 页面上有一个搜索栏,并希望返回一组过滤结果供用户从搜索栏中选择作为下拉列表。我将查询参数从搜索栏传递到 Laravel 控制器,并使用用户查询执行 where 子句:
public function showFilteredResponse(Request $request)
{
$query = $request->query('query'); //Query passed from Vue
$filteredResults = DB::table('documents')
->where('title', 'like', '%' . $query . '%')->get();
$filteredResults //this contains the data I want the front-end to have access to.
//how can this data be passed to Vue without a full page re-render?
}
如何在不重新渲染整个页面的情况下将 $filteredResults 数据返回给用户?要使用数据呈现初始页面,我有以下内容:
return Jetstream::inertia()->render($request, '/home')->with('documents', $documents);
但是,如果我想在不重新渲染的情况下向页面添加新数据,该怎么做呢?
如果我使用惯性()->render()->with(),那么我可以访问 Vue 页面上的 $filteredResults,但是我会从初始页面加载中丢失道具,除非我重复查询这似乎是正确的方法。
【问题讨论】:
-
为展示惯性.js 而制作的 PingCRM 演示项目有一个使用搜索的过滤选项。 Check out how it is done here.
标签: laravel inertiajs jetstream