# 深度拷贝

# deepClone

  • 代码示例:
<template>
    <div class="wrapper">
        <text>deepClone: 深度拷贝</text>
    </div>
</template>
<script>
export default {
    data:()=> ({
        name: 'deepCopy',
    }),
    methods: {
        cloneHandler() {
            let data = {
                name: 'dolphinWeex',
                keyName: ['dolphin', 'weex'],
                detail: {
                    type: 'framework'
                }
            }
            //数据深拷贝
            let res = this.$util.deepClone(data)
            data.detail.type = 'weex framework'
            this.$toast(res)
        }
    }
}
</script>
<style scoped>
.wrapper{
    background-color: #ffffff;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

# 参数

  • 成功时返回
Params Type Required default Value
obj any Y - 要拷贝的数据

# 深度合并

# deepMerge

  • 数据深度合并
<template>
    <div class="wrapper">
        <text>deepMerge: 深度合并</text>
    </div>
</template>
<script>
export default {
    data:()=> ({
        name: 'deepCopy',
    }),
    methods: {
        cloneHandler() {
            let target = {
                name: 'dolphinWeex',
                keyName: ['dolphin', 'weex'],
                detail: {
                    type: 'framework'
                }
            }
            let source = {
                name: 'dolphinWeex utils api',
                keyName: ['dolphin', 'weex','util', 'dev kit'],
                detail: {
                    type: 'function'
                }
            }
            //数据深拷贝
            let res = this.$util.deepMerge(target,source)
            this.$toast(res)
        }
    }
}
</script>
<style scoped>
.wrapper{
    background-color: #ffffff;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

# 参数

  • 成功时返回
Params Type Required default Value
target Object N {} 目标数据
source Object N {} 源数据
Last Updated: 2/1/2021, 11:33:56 AM