xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

_.cloneDeep & JSON deep copy bug All In One

_.cloneDeep & JSON deep copy bug All In One

deep clone / deep copy

_.cloneDeep 导致,from 对象的嵌套层次太深了

stack overflow

GC 爆栈


<--- Last few GCs --->

[50036:0x102808000]   649268 ms: Mark-sweep 1126.8 (1285.7) -> 1126.8 (1239.7) MB, 330.1 / 0.0 ms  (average mu = 0.938, current mu = 0.000) last resort GC in old space requested
[50036:0x102808000]   649520 ms: Mark-sweep 1126.8 (1239.7) -> 1126.8 (1228.2) MB, 251.6 / 0.0 ms 

_.cloneDeep bug

_.cloneDeep crashed the page, without show error information ❌

image

// app.vue

export default {
    // name: 'app',
    watch: {
        $route (to, from) {
            if(from.path.includes('/list/')) {
                this.$oldRoute = _.cloneDeep(from);
                console.log('from', from);
                console.log('this.$oldRoute', this.$oldRoute);
            }
        },
    },
    // ...
}

(JSON.parse & JSON.stringify) vanilla js , will show error information ✅

image

// app.vue

export default {
    // name: 'app',
    watch: {
        $route (to, from) {
            if(from.path.includes('/list/')) {
                this.$oldRoute = JSON.parse(JSON.stringify(from));
                console.log('from', from);
                console.log('this.$oldRoute', this.$oldRoute);
            }
        },
    },
    // ...
}

origin js

// app.vue

export default {
    // name: 'app',
    watch: {
        $route (to, from) {
            if(from.path.includes('/list/')) {
                // this.$oldRoute = _.cloneDeep(from);
                // this.$oldRoute = JSON.parse(JSON.stringify(from));
                this.$oldRoute = from;
                console.log('from', from);
                console.log('this.$oldRoute', this.$oldRoute);
            }
        },
    },
    // ...
}

refs



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @   xgqfrms  阅读(141)  评论(6编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2020-04-13 旅游玩乐 业务组件 UI 交互
2020-04-13 array auto slice
2020-04-13 trao 模拟点击 & js auto click
2020-04-13 alipay 小程序 & online IDE & demos
2020-04-13 macOS utils
2020-04-13 js 如何获取某一个月的第一天是周几
点击右上角即可分享
微信分享提示