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}
相关推荐
小鸡吃米…2 分钟前
Python - JSON
开发语言·python·json
Codebee4 分钟前
# 🔥A2UI封神!元数据驱动的AI交互新范式,技术人必看
前端·架构
JAVA+C语言6 分钟前
C#——接口
开发语言·c#
黎雁·泠崖7 分钟前
吃透指针通用用法:回调函数与 qsort 的使用和模拟
c语言·开发语言
whn19777 分钟前
达梦数据库的整体负载变化查看
java·开发语言·数据库
脏脏a9 分钟前
聊聊 C 里的进制转换、移位操作与算术转换
c语言·开发语言·移位操作符
陳103011 分钟前
C++:string(4)
开发语言·c++
ZHang......12 分钟前
synchronized(三)
开发语言·笔记·juc
JarvanMo12 分钟前
展望 2030 年:移动开发者的未来将如何?
前端
我的xiaodoujiao13 分钟前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 34--基础知识 9--文件上传功能
前端·python·测试工具·ui·pytest