gpt4 book ai didi

javascript - Vue - 将对象解构到 this(数据)

转载 作者:行者123 更新时间:2023-12-04 15:58:49 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Is it possible to destructure onto an existing object? (Javascript ES6)

(16 个回答)


去年关闭。




如何对我的 Vue 组件数据使用对象解构?
这是我的实际代码:

data: () => ({
descricao: '',
perfilBase: null,
anotherField: '',
otherOne: false
}),

mounted () {
this.descricao = this.$route.query.descricao
this.perfilBase = this.$route.query.perfilBase
}
我怎么能这样做?是否可以?
mounted () {
{ this.descricao, this.perfilBase } = ...this.$route.query
}

最佳答案

我认为没有一种方法可以像您想要的那样简洁。
你能做的最好的事情可能就是

mounted () {
const { descricao, perfilBase } = this.$route.query
this.descricao = descricao
this.perfilBase = perfilBase
}

关于javascript - Vue - 将对象解构到 this(数据),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62941744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com