Vue Diff Viewer

1.2.4 · maintenance · verified Sun Apr 19

Vue-diff is a Vue 3 component designed for rendering code differences in a user-friendly interface. It offers both split (side-by-side) and unified (inline) viewing modes, similar to those found in popular version control interfaces like GitHub Desktop. The component leverages `diff-match-patch` for its core diffing algorithm and `highlight.js` for robust syntax highlighting across various programming languages. Key features include support for customizable light and dark themes, virtual scrolling to efficiently handle large text comparisons, and a folding view for improved readability. It ships with TypeScript types, ensuring a good developer experience in TypeScript projects. The current stable version is 1.2.4, released in June 2022. While functional, its release cadence appears to be slow, suggesting a maintenance-focused development status rather than active feature expansion.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install and register `vue-diff` as a Vue 3 plugin, then use the `<Diff>` component to display a side-by-side comparison of two TypeScript code snippets with dark theme and virtual scrolling.

import { createApp } from 'vue';
import VueDiff from 'vue-diff';
import 'vue-diff/dist/index.css';

const app = createApp({
  template: `
    <div style="padding: 20px;">
      <h1>Code Diff Example</h1>
      <Diff
        mode="split"
        theme="dark"
        language="typescript"
        :prev="prevCode"
        :current="currentCode"
        :virtual-scroll="{ height: 300, lineMinHeight: 24, delay: 100 }"
      />
    </div>
  `,
  setup() {
    const prevCode = `
      function hello(name: string) {
        console.log('Hello, ' + name + '!');
        const age = 30;
        return name + age;
      }
    `;
    const currentCode = `
      function greeting(name: string) {
        console.log('Hi, ' + name + '!');
        const city = 'New York';
        return `Welcome, ${name} from ${city}`;
      }
    `;
    return { prevCode, currentCode };
  }
});

app.use(VueDiff, { componentName: 'Diff' });
app.mount('#app');

view raw JSON →