使用JSON.stringify报错:Uncaught TypeError: cyclic object value
- 具体错误
Uncaught TypeError: cyclic object value
onMouseOver Amap.vue:125
renderMarker Amap.vue:84
emit maps:1
emit maps:1
ci maps:1
ui maps:1
fireEvent maps:1
jL maps:1
Xt maps:1
T maps:1
<anonymous> amap.vue:49
promise callback*nextTick runtime-core.esm-bundler.js:242
<anonymous> amap.vue:48
promise callback* amap.vue:47
<anonymous> amap.vue:42
register useRegister.ts:102
useRegister useRegister.ts:64
node_modules chunk-A2DP46KH.js:8733
callWithErrorHandling runtime-core.esm-bundler.js:158
callWithAsyncErrorHandling runtime-core.esm-bundler.js:166
__weh runtime-core.esm-bundler.js:2655
flushPostFlushCbs runtime-core.esm-bundler.js:325
flushJobs runtime-core.esm-bundler.js:363
promise callback*queueFlush runtime-core.esm-bundler.js:270
queueJob runtime-core.esm-bundler.js:264
reload runtime-core.esm-bundler.js:464
tryWrap runtime-core.esm-bundler.js:494
<anonymous> Amap.vue:304
accept client.ts:564
fetchUpdate client.ts:481
queueUpdate client.ts:328
queueUpdate client.ts:328
handleMessage client.ts:181
handleMessage client.ts:179
setupWebSocket client.ts:96
setupWebSocket client.ts:95
<anonymous> client.ts:69
7 Amap.vue:125:35
- 解决办法
输出key和value,检查哪个是object类型,逐个排除。比如我经过输出,判断如下:
const onMouseOver = (event, marker) => {
let jsonString = JSON.stringify(event, function(key, value) {
//console.log(key+", "+value);
if (key === 'target') {
return undefined; // 忽略循环引用属性
}
return value;
});
console.log("event="+jsonString);
jsonString = JSON.stringify(marker, function(key, value) {
//console.log(key+", "+value);
if (key === 'context'
|| key === '_map'
|| key == '_parent' ) {
return undefined; // 忽略循环引用属性
}
return value;
});