Vue前端文本对比DIFF

介绍

前端文本比对找了几个库: 分别是: CodeMirror、DiffMatchPatch、Mergely、vue-code-diff,最后选择用:vue-code-diff

源码工程地址:DIFF

效果图

文本对比,两页显示效果:
在这里插入图片描述
文本对比,一页显示效果:
在这里插入图片描述

安装

npm install vue-code-diff

使用方式

import VueCodeDiff from 'vue-code-diff'

export default {
  name: 'diff_index',
  data: () => ({
    old_value: "/*以下为演示内容,请添加您自己的内容 ~_~ */\n" ,
    new_value: "/*以下为演示内容,请添加您自己的内容 ^_^ */\n", 
    context: 1000
  }),
  methods: {
    render_side_by_side(h) {
      return h('div', {}, [
        h('div', {
          staticClass: 'text-left text-tertiary font-14 text-weight-bold q-mt-md'
        }, [
          '两页显示对比结果,效果如下所示:'
        ]),
        h(VueCodeDiff, {
          props: {
            oldString: this.old_value,
            newString: this.new_value,
            context: this.context,
            outputFormat: 'side-by-side'
          }
        })
      ])
    },
    render_line_by_line(h) {
      return h('div', {}, [
        h('div', {
          staticClass: 'text-left text-tertiary font-14 text-weight-bold q-mt-md'
        }, [
          '一页显示对比结果,效果如下所示:'
        ]),
        h(VueCodeDiff, {
          props: {
            oldString: this.old_value,
            newString: this.new_value,
            context: this.context,
            outputFormat: 'line-by-line'
          }
        })
      ])
    },
  },
  render(h) {
    return h('div', {
      staticClass: 'q-pa-sm'
    }, [
      this.render_side_by_side(h),
      this.render_line_by_line(h)
    ])
  }
}

参数说明

参数说明类型可选值默认值
old-string旧值String--
new-string新值String--
context不同地方上下间隔多少行不隐藏Number--
outputFormat展示方式Stringline-by-line(一页显示),side-by-side(两页显示)line-by-line

插件地址:vue-code-diff

  • 7
    点赞
  • 61
    收藏
    觉得还不错? 一键收藏
  • 20
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值