这是我的第一篇帖子,我需要对一个定义在 "data "中的变量进行重构更新,我有以下代码片段。我需要重构更新一个定义在 "data "中的变量,我有以下代码片段。我使用的是VUE。
data: () => ({
id: '',
phone: '',
email: ''
}),
methods: {
async getId(){
{this.id, this.email, this.phone} = this.$route.query.item
}
}
其实你可以对现有的变量进行赋值。
只是语法有点奇怪。
这个应该可以
({id: this.id, phone: this.phone, email: this.email} = 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 })