[Vuejs]-Pass Data Via Object In Laravel Vue Form

0👍

The JSON structure is incorrect. You can’t use “.” as a key in the JSON structure.
if user is an object:
you can use like this code:

export default {
        props : [
            'user'
        ],
        methods : {
            profile() {
                var data = {};
                data[user.firstName] = this.user.firstName;
                data[user.lastName] = this.user.lastName;
                data[profile.code] = this.user.profile.code;
                axios
                    .put(`/web/me`, data)
                    .then((e) => {
                        window.location.href = '/profile';
                    })
                    .catch((e) => {
                        this.errors    = e.response.data.errors;

                    })
            },
        }
    }

user is not an object:

export default {
        props : [
            'user'
        ],
        methods : {
            profile() {
                var data = {
                  'user': {
                    'firstName': this.user.firstName,
                    'lastName': this.user.lastName,
                  },
                  'profile': {
                    'code': this.user.profile.code
                  }
                };
                axios
                    .put(`/web/me`, data)
                    .then((e) => {
                        window.location.href = '/profile';
                    })
                    .catch((e) => {
                        this.errors    = e.response.data.errors;

                    })
            },
        }
    }

0👍

Just change the name of your object key to be without a dot.

user.firstName : this.user.firstName

The previous is not a proper object key. You need to change it to the following:

userFirstName : this.user.firstName

Leave a comment