当前位置:网站首页>JS对象赋值问题
JS对象赋值问题
2022-07-26 10:35:00 【Suzerk】
Object.assign()
- 在使用element的过程中使用对象赋值
this.temp=this.listQuery在修改表格form中temp值的时候发现描述对象中的listQuery的数据一起改变。 - 最后发现,JS对象的赋值是默认引用赋值的。
查询相关资料,发现了可以使用Object.assign()解决
- 官方解释
Object.assign() 方法用于将所有可枚举属性的值从一个或多个源对象分配到目标对象。它将返回目标对象。
const target = {
a: 1, b: 2 };
const source = {
b: 4, c: 5 };
const returnedTarget = Object.assign(target, source);
console.log(target);
// expected output: Object {
a: 1, b: 4, c: 5 }
console.log(returnedTarget);
// expected output: Object {
a: 1, b: 4, c: 5 }
所以更改后this.temp = Object.assign({}, this.listQuery);这样就不会随之变化了。
边栏推荐
- Asynctask < T> decoration and await are not used in synchronous methods to obtain asynchronous return values (asynchronous methods are called in synchronous methods)
- MLX90640 红外热成像仪测温传感器模块开发笔记(六)红外图像伪彩色编码
- Redis Docker实例与数据结构
- 移动端双指缩放事件(原生),e.originalEvent.touches
- Application of.Net open source framework in industrial production
- 2022pta usual training questions (1-10 string processing questions)
- 404页面和路由钩子
- vscode上使用anaconda(已经配置好环境)
- uniapp使用简单方法signalR(仅用于web调试,无法打包app)
- Analyze the hybrid construction objects in JS in detail (construction plus attributes, prototype plus methods)
猜你喜欢

【机器学习小记】【人脸识别】deeplearning.ai course4 4th week programming

链式方法调用的事务问题剖析

抓包工具fiddler和wireshark对比

hx711 数据波动大的问题

Introduction to data analysis | kaggle Titanic mission (I) - > data loading and preliminary observation

vscode上使用anaconda(已经配置好环境)
控制随机抽中几率 [ C# | Random ]

Some cutting-edge research work sharing of SAP ABAP NetWeaver containerization

异常的概念与处理

Unit test, what is unit test and why is it so difficult to write a single test
随机推荐
.NET5WTM(ASP.NET Core) PGSql开箱操作
oracle 启动不了 tnslistener服务启动不了
Unit test, what is unit test and why is it so difficult to write a single test
json-c库的简单使用——将json文件转换为struct.
构造器、方法重载、对象数组和static
[Halcon vision] affine transformation
Introduction to Phoenix (Level 1: Phoenix installation, level 2: Phoenix basic grammar)
Modelsim installation tutorial (application not installed)
js翻页、kkpager.js翻页
[leetcode每日一题2021/5/8]1723. 完成所有工作的最短时间
结构体操作报错:Segmentation fault (core dumped)
The software cannot be opened
.net operation redis hash object
码云,正式支持 Pages 功能,可以部署静态页面
[leetcode每日一题2021/2/14]765. 情侣牵手
卸载魅族应用商店
[leetcode每日一题2021/8/30]528. 按权重随机选择【中等】
.NET 开源框架在工业生产中的应用
Problems encountered in QRcode QR code (C language)
.NET操作Redis List列表