0

我在 Laravel Inertia 中使用动态查询,我的分页出错了,因为每次我尝试更改分页时 vue 的 mount() 方法都会运行。

 data() {
        return {
            form: this.$inertia.form({
                search: this.filters.search,
                order: "asc",
                column: "code",
                size: 5,
            }),
        };
    },
    mounted() {
        this.$inertia.get(this.route("groups.index"), pickBy(this.form), {
            preserveState: true,
        });
    },
    watch: {
        form: {
            deep: true,
            handler: throttle(function () {
                this.$inertia.get(
                    this.route("groups.index"),
                    pickBy(this.form),
                    { preserveState: true }
                );
            }, 150),
        },
    },

我只需要在第一次使用 mount() 或组件被渲染,但我不希望 mount() 函数在每次使用或更改分页时都运行,有什么解决方法吗?

'groups' => Group::where('company_id', Auth::user()->company_id)
            ->when($request->search, function($query, $term){
                $query->where('code', 'LIKE' , '%' . $term. '%')
                      ->orWhere('name', 'LIKE' , '%' . $term. '%')
                      ->orWhere('description', 'LIKE' , '%' . $term. '%');
            })->when($request->column, function($query, $term) use ($request){
                $query->orderBy($term, $request->order);
            })->paginate($request->size)->withQueryString(),

这是我的查询。

4

0 回答 0