[Vuejs]-Vuejs function with multiple data

0👍

If you mean to have the two data in one object, you can make a new object from the two objects

Es6 Example:

            const {bank,id} = this.upload;
            const {cash} = this.cash;
            const my_data = {
                bank, id, cash
            }

Older Js example

            var my_data = {
                cash: this.cash.cash,
                bank: this.upload.bank,
                id: this.upload.id,
            }

Otherwise, if you want to have both in the request as separate objects then wrap around them {}

            var my_data = {
                upload: this.upload,
                cash: this.cash
            }

Finally:

            axios.put('/updatebank', my_data)
                ...

Update: It appears you don’t want to merge those objects as different sub-object so your updateBank method would be like so:

    updateBank: function () {
        const my_data = {
            cash: this.cash.cash,
            bank: this.upload.bank,
            id: this.upload.id,
        };

        axios.put('/updatebank', my_data)
            .then(response => {
                if (response.data.etat) {
                    this.upload.id = response.data.etat.id
                    this.upload.bank = response.data.etat.bank
                    this.cash.cash = response.data.etat.cash

                }

            })
            .catch(error => {
                console.log('errors: ', error)
            });
    }

Just a side observation, are you sure the this in the response references your Vue object?

Leave a comment