Vue diff viewer
npm install vue-diffVue diff viewer plugin for Vue@3
demo
- Table of Contents
- Introduction
- Features
- Install plugin
- Options
- Usage diff viewer
- Settings with default props
- Settings with full props
- Props
- Custom theme
- Extend languages
- Default supported languages and values
- Virtual scroll
- Object props

You can see the difference between the two codes with the vue-diff plugin.
This plugin dependent on diff-match-patch and highlight.js, shows similar results to other diff viewers (e.g., Github Desktop).
Here is the demo
- Support split / unified mode
- Support multiple languages and can be extended
- Support two themes (dark / light) and can be customized
- Virtual scroll for large text comparison
- Folding view (_Partial folding is not supported_)
- Support typescript
``bash`
npm install vue-diff
And install plugin in vue application
`ts
import VueDiff from 'vue-diff';
import 'vue-diff/dist/index.css';
app.use(VueDiff);
`
`ts`
app.use(VueDiff, {
componentName: 'VueDiff',
});
| name | type | detault | description |
| ------------- | -------- | ------- | -------------------------- |
| componentName | string | Diff | Global diff component name |
Insert the diff component with props.
`vue`
:theme="theme"
:language="language"
:prev="prev"
:current="current"
/>
`vue`
:theme="theme"
:language="language"
:prev="prev"
:current="current"
:folding="folding"
:input-delay="0"
:virtual-scroll="{ height: 500, lineMinHeight: 24, delay: 100 }"
/>
| name | type | detault | values | description |
| ------------- | ----------------- | ----------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| mode | string | split | split, unified |string
| theme | | dark | dark, light, custom${string} | See Custom theme |string
| language | | plaintext | | See Extend languages |string
| prev | | '' | | Prev code |string
| current | | '' | | Current Code |boolean
| folding | | false | | Folding not different |number
| inputDelay | | 0 | | Setting up rendering debounce for changes for performance benefit (mode, prev, curr) |boolean\|object
| virtualScroll | | false | | _Default value when setting true :_{ height: 500, lineMinHeight: 24, delay: 100 }
See virtual scroll |
vue-diff uses the following highlight.js themes and can be customized.
- dark: highlight.js/scss/monokai.scsshighlight.js/scss/vs.scss
- light:
`bash`
npm install highlight.js
`vue
theme="custom"
:language="language"
:prev="prev"
:current="current"
/>
`
vue-diff supports the following languages and can be extended through highlight.js language registration.
- cssxml
- : xml, html, xhtml, rss, atom, xjb, xsd, xsl, plist, svgmarkdown
- : markdown, md, mkdown, mkdjavascript
- : javascript, js, jsxjson
- plaintext
- : plaintext, txt, texttypescript
- : typescript, ts
`bash`
npm install highlight.js
`ts
import VueDiff from 'vue-diff';
import 'vue-diff/dist/index.css';
// extend yaml language
import yaml from 'highlight.js/lib/languages/yaml';
VueDiff.hljs.registerLanguage('yaml', yaml);
app.use(VueDiff);
`
> Check supported languages of Highlight.js
Comparing text from many lines can slow down performance.
With virtualScroll props, virtualScroll applies. (Self-made for this plug-in.)
#### Object property value
When using virtual scroll, the css of all code lines is changed to the absolute position, which requires detailed settings.
- height (number): Diff box height (Applies only to px values)number
- lineMinHeight (): minimum height of linenumber`): re-rendering delay when scrolling or resizing
> Minimum height value of line is required for visible area calculation.
The default is 24, but you can set it yourself if you need to adjust it according to the page's front-size, line-height, etc.
- delay (
> Performance problems occur when too often a re-rendering function is invoked based on scrolling or resizing
This setting applies a delay using throttle.