小编在进行对象合并{….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为不可
解决办法
const c = {...a,...b} ---> a不可拓展
const ob = {...a} // 浅拷贝
const c = {...ob,...b}