简体   繁体   English

PUT http://localhost:3000/events/undefined 404(未找到)

[英]PUT http://localhost:3000/events/undefined 404 (Not Found)

this code updates a specific object by taking it's id.此代码通过获取它的 id 来更新特定的 object。 when i hard code the id into the API cal, there is no error and it works just fine, but when i pass the id that it gets from the component in a new argument into the 'updateEvent' function it returns undefined id.当我将 id 硬编码到 API cal 中时,没有错误并且它工作得很好,但是当我将它从新参数中的组件获取的 id 传递到“updateEvent”function 中时,它返回未定义的 id。 i think the problem is inside the vuex code inside the parameters that I'm passing我认为问题出在我传递的参数中的 vuex 代码内部

axios API call axios API 调用

updateEvent(id, event) {
        return apiClient.put(`/events/${id}`, event)
}

and in vuex actions在 vuex 动作中

updateEvent({
      commit,
      dispatch
    }, {
      id,
      event
    }) {
      return EventService.updateEvent(id, event)
        .then(() => {
          commit('UPDATE_EVENT', event)
        })
    }

and I dispatched it inside my component like this我像这样在我的组件中发送它

methods: {
    updateEvent() {
      this.$store
        .dispatch("updateEvent", this.id, this.event)
        .then(() => {
          this.$router.push({
            name: "EventShow",
            params: { id: this.id },
          });
        })
        .catch(() => {});
    },
  }

Your action unpacks/destructures id and event from the payload (the 2nd argument), but your dispatch is not passing an object.您的操作从有效负载(第二个参数)中解包/解构idevent ,但您的调度未传递 object。 Instead, it's passing this.id -- presumably a String , which does not contain a property named id or event (hence, id resolves to "undefined" in your URL).相反,它传递的是this.id - 大概是一个String ,它不包含名为idevent的属性(因此, id在您的 URL 中解析为“未定义”)。

To resolve the problem, your dispatch should pass an object with the expected properties:要解决此问题,您的调度应传递具有预期属性的object

//this.$store.dispatch("updateEvent", this.id, this.event); // DON'T DO THIS
this.$store.dispatch("updateEvent", { id: this.id, event: this.event })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 POST http://localhost:3000/undefined/post 404(未找到) - POST http://localhost:3000/undefined/post 404 (Not Found) POST http:// localhost:3000/404(未找到) - POST http://localhost:3000/ 404 (Not Found) http://localhost/undefined 404(未找到) - http://localhost/undefined 404 (Not Found) 发布 http://localhost:3000/api/auth/register 404(未找到) - POST http://localhost:3000/api/auth/register 404 (Not Found) POST http://localhost:3000/api/customers 404(未找到)reactjs nodejs - POST http://localhost:3000/api/customers 404 (Not Found) reactjs nodejs POST http://localhost:3000/api/login 404(未找到) - POST http://localhost:3000/api/login 404 (Not Found) React.js / Firebase 应用程序中的 Axios 错误(404):POST http://localhost:3000/login 404(未找到) - Axios error (404) in React.js / Firebase app: POST http://localhost:3000/login 404 (Not Found) 我不断收到 http POST http://localhost:3000/api/authenticate 404(未找到) - I keep getting http POST http://localhost:3000/api/authenticate 404 (Not Found) 发布 localhost:3000/api/users 404 未找到 - Post localhost:3000/api/users 404 not found <undefined:1 GET http://localhost:63342/Twitchtv/undefined 404 (Not Found)> - <undefined:1 GET http://localhost:63342/Twitchtv/undefined 404 (Not Found)>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM