js中对象发生不可拓展问题

小编在进行对象合并{....a,....b}的时候发生了如下报错

报错如下

Uncaught runtime errors:

×

ERROR

Cannot assign to read only property 'password' of object '#'

TypeError: Cannot assign to read only property 'password' of object '#'

at createUser (http://localhost:3000/static/js/src_view_Registered_registered_js.chunk.js:43:19)

at submit (http://localhost:3000/src_view_Registered_registered_js.186aa687e8d666b41197.hot-update.js:51:79)

at onFinish (http://localhost:3000/static/js/vendors-node_modules_antd_es__util_colors_js-node_modules_antd_es_divider_index_js-node_modul-7e8d3b.chunk.js:8195:9)

at http://localhost:3000/static/js/vendors-node_modules_antd_es__util_colors_js-node_modules_antd_es_divider_index_js-node_modul-7e8d3b.chunk.js:9460:11

检查对象是否支持拓展

console.log(Object.isExtensible(对象)) true为可,false为不可

解决办法

js 复制代码
const c = {...a,...b} ---> a不可拓展
const ob = {...a} // 浅拷贝
const c = {...ob,...b}
相关推荐
萑澈4 小时前
Windows 7 运行 Electron 安装包报“不是有效的 Win32 应用程序”怎么办
javascript·windows·electron
W.A委员会5 小时前
JS原型链详解
开发语言·javascript·原型模式
止语Lab5 小时前
Go并发编程实战:Channel 还是 Mutex?一个场景驱动的选择框架
开发语言·后端·golang
懂懂tty5 小时前
React状态更新流程
前端·react.js
小码哥_常5 小时前
告别繁琐!手把手教你封装超实用Android原生Adapter基类
前端
她说彩礼65万6 小时前
C# 实现简单的日志打印
开发语言·javascript·c#
绿浪19846 小时前
c# 中结构体 的定义字符串字段(性能优化)
开发语言·c#
skywalk81636 小时前
pytest测试的时候这是什么意思?Migrating <class ‘kotti.resources.File‘>
前端·python
房开民6 小时前
可变参数模板
java·开发语言·算法
一只蝉nahc6 小时前
vue使用iframe内嵌unity模型,并且向模型传递信息,接受信息
前端·vue.js·unity