AI编程助手
AI免费问答

如何在Laravel的Inertia/Vue中实现效率最高的数据库搜索方法

<p>我想要搜索客户列表并按原样更改组件。</p> <p>目前我使用此链接搜索特定客户 /customer/$searchColumn/$searchTerm?page=4</p> <p>这是我的控制器返回的内容</p> <pre class="brush:php;toolbar:false;">return Inertia::render('Dashboard', [ 'customers' =&gt; Customer::whereLike("nr", (string)$request)-&gt;paginate(10), ]);</pre> <p>渲染一个带有分页的所有找到的项目的表格。</p> <p>Vue目前非常简单:</p> <pre class="brush:php;toolbar:false;"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script setup&gt; import { usePage } from '@inertiajs/vue3' import Pagination from '@/mycompany/Pagination.vue'; const page = usePage() &lt;/script&gt;</code></pre> <code> </code></pre> <p>在前端,我用以下方式渲染一个表格:</p> <pre class="brush:php;toolbar:false;"> <pre class="snippet-code-js lang-js prettyprint-override"><code>v-for="customer in $page.props.customers.data"</code></pre> <code> </code></pre> <p>我想要一个位于表格顶部的搜索框,当我输入时重新加载结果。</p> <p>我不知道从哪里开始。</p>
# Vue.js
P粉458725040 P粉458725040 686 天前 818 次浏览

全部回复(1) 我要回复

  • P粉903969231

    P粉9039692312023-08-16 00:01:21

    对于这种情况,您可以使用常规的ajax/fetch请求来完成。

    Inertia仍然利用laravel进行路由,所以没有某种请求或重定向是不可能完成这种表单请求的。

    甚至inertia.js的创建者也支持使用xhr/fetch请求与inertia一起使用

    回复
    0
  • 取消 回复 发送