我需要解构一个对象来更新数据中定义的变量

I need to unstructure an object to update the variables defined in data

这是我的第一个 post。我需要解构以更新 "data" 中定义的变量,我有以下代码片段。我正在使用 VUE。

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

你不能解构现有的道具,只能解构新的道具:

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

实际上你可以赋值给已有的变量。

语法有点奇怪。

这应该有效

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

这是一个working example