Vue 学习笔记(四十三):Vue JSON diff

使用 https://github.com/ddchef/vue-code-diff 即可

效果

源码

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
39
40
41
42
43
44
45
46
47
48
49
50
<template>
<section>
<h3>side-by-side</h3>
<div>
<code-diff
:old-string="oldStr"
:new-string="newStr"
outputFormat="side-by-side"
:context="10"
>
</code-diff>
</div>
<br />
<h3>line-by-line</h3>
<div>
<code-diff
:old-string="oldStr"
:new-string="newStr"
:context="10"
>
</code-diff>
</div>
</section>
</template>
<script>
import CodeDiff from "vue-code-diff";
export default {
name: "JSONCompare",
components: { CodeDiff },
data() {
return {
oldStr: "",
newStr: ""
};
},
mounted() {
this.getgrouplist();
},
methods: {
getgrouplist() {
let oldJSON = {"status":0, "measures":[{"metric":"coverage","value":"0.0","periods":[{"index":1,"value":"0.0"}],"component":"aaa"}]}
let newJSON = {"measures":[{"metric":"coverage","value":"0.0","periods":[{"index":2,"value":"0.0"}],"component":"bbb"}]}
this.oldStr = JSON.stringify(oldJSON, null, 4);
this.newStr = JSON.stringify(newJSON, null, 4);
},
}
};
</script>
<style scoped>
</style>