【问题标题】:The PUT method is not supported for this route. Vue/laravel此路由不支持 PUT 方法。 Vue/laravel
【发布时间】:2021-11-30 20:19:52
【问题描述】:

当我尝试更新产品时,我的 vue 组件出现问题,它返回错误 put method is not supported... 但应该支持。

我的 EditProduct.vue

<form @submit.prevent="submitForm">
   <div class="form-group row">
     <label for="name" class="col-md-4 col-form-label text-md-right">Name:</label>
     <input type="text" name="name" id="name" v-model="product.name">
   </div>
   <div class="form-group row">
     <label class="col-md-4 col-form-label text-md-right">Description:</label>
     <textarea name="description" cols="20" rows="5" v-model="product.description"></textarea>
   </div>
   <div style="display: flex; justify-content: center">
     <button type="submit">Save</button>
   </div>
</form>

我的提交方法:(我尝试了 axios.post 的补丁/安装但它仍然不起作用)

    submitForm(){
        let data = new FormData();
        data.append('_method', 'PUT');
        data.append('id', this.product.id);
        data.append('name', this.product.name);
        data.append('description', this.product.description);
        axios.post('edit', data)
        .then( (response) => {
            console.log("success");
        })
    }

我的 api 路由:

Route::put('/edit', [ProductController::class, 'update']);

我在这里做错了什么?

【问题讨论】:

    标签: laravel vue.js vuejs2 axios laravel-8


    【解决方案1】:

    当我发布问题时,我意识到 axios 的 url 是错误的,它应该是错误的

    /api/编辑

    它现在可以工作了:)

    【讨论】:

      猜你喜欢
      • 2020-04-03
      • 2019-11-14
      • 1970-01-01
      • 1970-01-01
      • 2020-01-23
      • 1970-01-01
      • 2020-04-13
      • 2020-02-16
      • 1970-01-01
      相关资源
      最近更新 更多