js vue Deep Copy löst das Problem einer Änderung und die andere ändert sich auch entsprechend

function deepClone(source) {
    
    
  if (!source && typeof source !== 'object') {
    
    
    throw new Error('error arguments', 'deepClone')
  }
  const targetObj = source.constructor === Array ? [] : {
    
    }
  Object.keys(source).forEach(keys => {
    
    
    if (source[keys] && typeof source[keys] === 'object') {
    
    
      targetObj[keys] = deepClone(source[keys])
    } else {
    
    
      targetObj[keys] = source[keys]
    }
  })
  return targetObj
}


Supongo que te gusta

Origin blog.csdn.net/qq_38946996/article/details/133167427
Recomendado
Clasificación