0%

codemirror文件比对

文件比对

codemirror && diff-match-patch

官网示例
demo
diff-match-patch issue

vue 整合

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
npm install codemirror
npm install diff-match-patch

<template>
<div id="view"></div>
</template>
<script>
import CodeMirror from 'codemirror'
import 'codemirror/lib/codemirror.css'
import 'codemirror/addon/merge/merge.js'
import 'codemirror/addon/merge/merge.css'
import DiffMatchPatch from 'diff-match-patch'
window.diff_match_patch = DiffMatchPatch
window.DIFF_DELETE = -1
window.DIFF_INSERT = 1
window.DIFF_EQUAL = 0
export default {
name: 'Diff',
mounted () {
let value = 'abcc'
let orig2 = 'abcd'
this.initUI(value, orig2)
},
methods: {
initUI (value, orig2) {
if (value == null) {
return
}
let target = document.getElementById('view')
target.innerHTML = ''
CodeMirror.MergeView(target, {
value: value, // 上次内容
origLeft: null,
orig: orig2, // 本次内容
lineNumbers: true, // 显示行号
mode: 'text/html',
highlightDifferences: true,
connect: 'align',
revertButtons: true, // 是否显示还原按钮
readOnly: true// 只读 不可修改
})
}
}
}
</script>
<style scoped>
</style>
  • 效果