[Vuejs]-I need to unstructure an object to update the variables defined in data

2👍

Actually you can assign to existing variables.

The syntax is just a little weird.

This should work

({id: this.id, phone: this.phone, email: this.email} = this.$route.query.item)

Here’s a working example

1👍

You can’t destructure to existing props but to new ones only:

data () {
    return {
     item: {
       id: '',
       phone: '',
       email: ''
     }
   }
},
...
methods: {
 async getId(){
   { id, email, phone } = this.$route.query.item
   Object.assign(this.item, { id, email, phone })

Leave a comment