将属性从json对象复制到此范围

时间:2018-03-13 08:19:40

标签: javascript vue.js

我们可以使用扩展运算符重写此代码还是以其他方式简化?

        this.activeCategory = json.activeCategory
        this.activeParent = json.activeParent
        this.openMenu = json.openMenu
        this.showMobile = json.showMobile

我在vue's mounted hook

中使用它

1 个答案:

答案 0 :(得分:1)

您可以使用与Object.assign

配对的展开运算符
const temp = { activeCategory, activeParent, openMenu, showMobile } = json;
Object.assign(this, temp);