Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

数组拷贝问题=>页面管理-第二次打开存在一些问题 #3

Open
vicksiyi opened this issue Mar 3, 2022 · 3 comments
Open

Comments

@vicksiyi
Copy link
Owner

vicksiyi commented Mar 3, 2022

No description provided.

@vicksiyi
Copy link
Owner Author

vicksiyi commented Mar 3, 2022

js 浅拷贝 子数组问题

@vicksiyi
Copy link
Owner Author

vicksiyi commented Mar 3, 2022

let original = {
    key1: '',
    key2: '',
    key3: [],
    key4: ''
}

let dist = Object.assign({}, original);
dist.key3.push(123);
console.log(dist);
console.log(original);
// { key1: '', key2: '', key3: [ 123 ], key4: '' }
// { key1: '', key2: '', key3: [ 123 ], key4: '' }

@vicksiyi
Copy link
Owner Author

vicksiyi commented Mar 3, 2022

解决方案:
JSON.parse(JSON.stringify(original))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant