Vue对象复制 数组复制 复制数组 浅复制 深复制 对象引用

对象复制

javascript 复制代码
// 对象复制
this.documentsTemp = Object.assign({}, this.documentsInit)

数组复制

javascript 复制代码
// 数组复制是用slice()
this.documentsTemp = this.documentsInit.slice()

完整示例

javascript 复制代码
// 赋值(赋引用 实质是两个指向同一个对象)
this.form = res.data
// 对象复制,初始化 清缓存,不能使用简单赋值语句 是指向同一个对象 应使用对象复制方式
// this.documentsTemp = Object.assign({}, this.documentsInit)
// 数组复制是用slice()
this.documentsTemp = this.documentsInit.slice()
// like12 add,20230924,电子档案处理
if (res.data.documents && res.data.documents.length > 0) {
  res.data.documents.forEach(e => {
    this.documentsTemp[e.fileFlag] = e
  })
}
this.form.documents = this.documentsTemp

参考:

Vue复制对象详解_笔记大全_设计学院

Object.assign详解_我带你们飞的博客-CSDN博客

相关推荐
老毛肚2 小时前
jeecg-boot-base-core 02 day
javascript·python
岁月宁静3 小时前
RAG 文档摄入全链路,从原理到生产落地
vue.js·人工智能·python
#麻辣小龙虾#5 小时前
基于vue3.0开发一款【固废与废气运维管理系统】(支持源码)
前端·vue.js·vue3
一 乐6 小时前
家政服务管理系统|基于springboot + vue家政服务管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·家政服务管理系统
烬羽7 小时前
后端返回的 JSON 字符串,浏览器怎么"看懂"的?——Ajax 全链路拆解
javascript
半个落月8 小时前
一个新手用 Bun + Axios 调通 DeepSeek API 的实践记录
javascript
不好听6138 小时前
深入理解链表:线性数据结构的另一面
javascript·数据结构
林希_Rachel_傻希希8 小时前
学React治好了我的焦虑症,1小时速通React 前20分钟。
前端·javascript·面试
小林ixn8 小时前
从 Ajax 到异步编程:JSON 序列化、Event Loop 与 XHR 请求完全解析
javascript
丷丩9 小时前
MapLibre GL JS第47课:添加动画图标
javascript·gis·动画·mapbox·maplibre