Home > Software design >  Axios sending a status201 for a put method using a form on vue3 but nothing change
Axios sending a status201 for a put method using a form on vue3 but nothing change

Time:07-24

I want to change my user personnal infos using axios. I created the form and the axios method. When i send the form i do have the status(201) but the data doesnt change ! But it does change if i do it on postman...

Here is my code !

<form >
                                <div>
                                    <p>Changer de prénom</p>
                                    <input type="text" v-model="user.firstname" placeholder="Changer de prénom" />
                                </div>
                                
                                <div>
                                    <p>Changer de nom de famille</p>
                                    <input type="text" v-model="user.lastname" placeholder="Changer de nom de famille" />
                                </div>
                                
                                <div>
                                    <p>Changer d'adresse mail</p>
                                    <input type="email" v-model="user.email" placeholder="Changer d'adresse mail" />
                                </div>
                                
                                <div>
                                    <p>Changer de mot de passe</p>
                                    <input v-model="user.password" type="password" placeholder="Changer de mot de passe" />
                                </div>
                                <br />
                            </form>
updateUser() {
            const formData = new FormData();
            formData.append("firstname", this.user.firstname);
            formData.append("lastname", this.user.lastname);
            formData.append("email", this.user.email);
            formData.append("password", this.user.password);
            axios
                .put("http://127.0.0.1:3000/api/auth/", formData,
                    {
                        headers: {
                            Authorization: "Bearer "   localStorage.getItem("token"),
                        },
                    })
                .then((formData) => {
                    console.log(formData)
                    this.user.firstname = "";
                    this.user.lastname = "";
                    this.user.email = "";
                    this.user.password = "";
                })
                .catch((error) => console.log(error));
        },

Thanks for the help !!!

CodePudding user response:

Figured out by myself.

i stored the userId, firstname and lastname in the localStorage on login then i did

formData.append('firstname', localStorage.getItem("firstname"));
            formData.append('lastname', localStorage.getItem("lastname"));
            formData.append('userId', localStorage.getItem("userId"));

dont know if its the right way to do it but it works so...

  • Related