繁体   English   中英

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

[英]copying properties from json object to this scope

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

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

我在vue's mounted钩中使用它

您可以使用与Object.assign配对的散布运算符

const temp = { activeCategory, activeParent, openMenu, showMobile } = json;
Object.assign(this, temp);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM