惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - dnddn

axios输出图片显示 ElementUI时间选择控件提交的时间为UTC时间 pypi清华镜像 通过Access-Control-Allow-Origin解决跨域问题 解决mac下mysql libssl.1.0.0.dylib报错问题 Google App Engine初探 SQL2005的阀值设定 移动硬盘识别不了的问题 网球术语英汉对照 【丰富词汇量,喜欢网球的路过说声。。】 几个小问题 - dnddn - 博客园 SilverLight,有多少人关心呢? be my friend MSSQL中的随机函数 检讨 简单的就是最好的 这个五一 紧张非封闭式开发中 静静的看twittervision SQL Server 2005 数据类型
JS引用传值问题
dnddn · 2020-09-18 · via 博客园 - dnddn

问题:在Vue页面中将C变量赋值给A、B,然后修改A值,发现B也给变了。

var c = [1,2,3,4];
var a = c;
var b = c;
a.pop();

console.log(a) //[1,2,3]
console.log(b) //[1,2,3]
console.log(c) //[1,2,3]

如上,此处传值是引用传递而不是值传递。那么,如何解决呢?

var c = [1,2,3,4];
var a = c;
var b = JSON.parse(JSON.stringify(c));
a.pop();

console.log(a) //[1,2,3]
console.log(b) //[1,2,3,4]
console.log(c) //[1,2,3]

如此,采用深克隆的方式把数值转换成字符串,然后再转换成对象。问题解决。修改a的值,b的值不变。