const a = {
'weight': 1,
'server': '',
'upstreamType': 'http'
}
const b = [{
'weight': 1,
'server': '',
'upstreamType': 'http'
}, {
'weight': 1,
'server': '',
'upstreamType': 'http'
}]
-- 对象深拷贝
const obj = JSON.parse(JSON.stringify(a))
-- 数组深拷贝
const arr = JSON.parse(JSON.stringify(b))
console.log(obj)
结果: { weight: 1, server: '', upstreamType: 'http' }
console.log(arr)
结果: [
{ weight: 1, server: '', upstreamType: 'http' },
{ weight: 1, server: '', upstreamType: 'http' }
]
vue~对象数组深拷贝,不改变原数据结构
最新推荐文章于 2024-06-21 13:58:05 发布