[Vuejs]-Can't update record after creating record Vue.js/Vuetify/Axios

0๐Ÿ‘

  1. Some props are missing in data block, for instance this.res, this.response
  2. First you should send axios request and AFTER that change this.companies:
    instead of
Object.assign(this.companies[this.editedIndex], this.editedItem);
        try {
          let res = await axios.post(
            "http://localhost:8888/api_test/config-panel/client.php?method=updateCustomer",
            {
              id: this.editedItem.ID,
              name: this.editedItem.name,
              telephone: this.editedItem.telephone,
              email: this.editedItem.email,
              website: this.editedItem.website,
              location: this.editedItem.location
            }
          );

you should first send POST request:

        try {
          let res = await axios.post(
            "http://localhost:8888/api_test/config-panel/client.php?method=updateCustomer",
            {
              id: this.editedItem.ID,
              name: this.editedItem.name,
              telephone: this.editedItem.telephone,
              email: this.editedItem.email,
              website: this.editedItem.website,
              location: this.editedItem.location
            }
          );
          Object.assign(this.companies[this.editedIndex], this.editedItem);
  1. A server-side method for POST should return ID of a newly created item. Then this ID should be placed in this.editemItem before appending it to companies array

The same goes for PUT (except p.3)

Leave a comment