【问题标题】:Uncaught Error: Ziggy error: 'x' parameter is required for route 'y' even if 'x' parameter has been provided未捕获的错误:Ziggy 错误:即使提供了“x”参数,路由“y”也需要“x”参数
【发布时间】:2021-09-07 14:12:41
【问题描述】:

我不断收到此错误。 我的应用有用于搜索产品的 vue 组件:

<template>
    <form @submit.prevent="searchProduct">
        <input
            placeholder="Search"
            v-model="form.q"
            type="search"/>
    </form>
</template>

<script>
export default {
    data() {
        return {
            form: this.$inertia.form({
                _method: "get",
                q: '',
            }),
        };
    },
    methods: {
        searchProduct() {
            this.form.get(route('search.product', {q : this.q}), {
                errorBag: "validate_q",
                preserveScroll: true,
            });
        },
    },
};
</script>

在我的 web.php 中


// Search product
Route::get('search/{q}', [ProductController::class, 'search'])->name('search.product');

我想知道为什么会发生这个错误?我使用 Laravel jetstream +惯性js

【问题讨论】:

    标签: laravel inertiajs


    【解决方案1】:

    我相信您错过了对表单的引用:

    // replace this
    this.form.get(route('search.product', {q : this.q}), {
    
    // with this
    this.form.get(route('search.product', {q : this.form.q}), {
    

    另外,请注意,您将 q 作为路由参数传递,并将 ALSO 作为查询字符串参数传递。

    form: this.$inertia.form({
       _method: "get",
       q: '', // this will be passed as a query string param
    }),
    

    【讨论】:

    • 我也面临同样的问题。但它不起作用。
    猜你喜欢
    • 2023-03-17
    • 2022-12-16
    • 2017-05-06
    • 1970-01-01
    • 2023-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    相关资源
    最近更新 更多