Vue Document Preview Component

0.3.2 · active · verified Wed Apr 22

Vue-doc-preview is a Vue.js component designed to embed and display various document types directly within a web application. It supports rendering markdown, plain text, code with syntax highlighting, and can even fetch and display office documents (docx, pptx, xlsx) from a provided URL. The current stable version is 0.3.2, with recent minor releases indicating active development and feature additions like URL-based document loading and request configuration since v0.3.0. A key differentiator is its ability to handle multiple formats and integrate custom styling for markdown and text, while maintaining a relatively small footprint. It offers flexibility by allowing content to be passed directly via a `value` prop or fetched remotely via a `url` prop.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to embed `VueDocPreview` to display markdown content with custom code block styling, fetch and render an office document from a public URL, and display a TypeScript code snippet with highlighting.

<template>
  <div style="padding: 20px; font-family: sans-serif;">
    <h1>Document Previews</h1>

    <h2>Markdown Preview</h2>
    <VueDocPreview
      :value="markdownContent"
      type="markdown"
      :mdStyle="mdStyle"
      style="border: 1px solid #ddd; border-radius: 6px; padding: 15px; margin-bottom: 30px; background-color: #fff;"
    />

    <h2>Office Document from URL</h2>
    <!-- Note: Ensure the URL is publicly accessible and provides appropriate CORS headers for preview. -->
    <VueDocPreview
      url="https://newteach.pbworks.com/f/ele%20newsletter.docx"
      type="office"
      height="500"
      style="border: 1px solid #ddd; border-radius: 6px; margin-bottom: 30px; background-color: #f9f9f9;"
    />

    <h2>Code Preview (TypeScript)</h2>
    <VueDocPreview
      :value="codeSnippet"
      type="code"
      language="typescript"
      style="border: 1px solid #ddd; border-radius: 6px; padding: 15px; margin-bottom: 30px; background-color: #2d2d2d; color: #f8f8f2;"
    />
  </div>
</template>

<script>
import VueDocPreview from 'vue-doc-preview'

export default {
  components: {
    VueDocPreview
  },
  data() {
    return {
      markdownContent: "# VueDocPreview Demo\n\nThis is a **markdown** test with `code snippets`.\n\n```javascript\nfunction helloWorld() {\n  console.log('Hello from VueDocPreview!');\n}\n\nhelloWorld();\n```\n\n- List item one\n- List item two\n\nA blockquote example:\n> This is a quote.\n",
      mdStyle: {
        pre: {
          'background-color': '#282c34',
          'color': '#abb2bf',
          'padding': '1em',
          'border-radius': '6px',
          'overflow-x': 'auto'
        },
        code: {
          'color': '#abb2bf',
          'font-family': 'monospace',
          'font-size': '0.9em'
        }
      },
      codeSnippet: `interface User {
  id: number;
  name: string;
  email?: string;
}

const users: User[] = [
  { id: 1, name: 'Alice' },
  { id: 2, name: 'Bob', email: 'bob@example.com' }
];

function findUserById(id: number): User | undefined {
  return users.find(user => user.id === id);
}

console.log(findUserById(1));
`
    }
  }
}
</script>

view raw JSON →