DEV Community

Cover image for Display Vue examples inside VuePress documentation
Giannis Koutsaftakis
Giannis Koutsaftakis

Posted on • Edited on

4 1

Display Vue examples inside VuePress documentation

Writing documentation with VuePress is a breeze! Not only does it have support for Markdown files that get automatically converted to HTML, but it also contains a big collection of Markdown extensions out-of-the-box, including syntax highlighting in code blocks. But that's not all, it also includes site search capability, i18n, custom themes, and the list goes on.

One of the best features though is that you can use Vue components directly inside your Markdown files, thus making it the perfect documentation tool for Vue projects.

What's often needed while documenting software projects is to display "live" examples along with the source code side-by-side. This is where vuepress-plugin-vue-example comes in. It's a VuePress plugin that uses Vue SFCs for displaying Vue examples inside VuePress documentation pages.

The plugin is inspired by a similar functionality available on the Vuetify documentation site.

How it works:

Upon initialization of the plugin you have to provide the folder in which all your examples reside. The examples will be just regular .vue SFC files.

// .vuepress/config.js
const VueExamplePlugin = require('vuepress-plugin-vue-example');

module.exports = {
  plugins: [
    VueExamplePlugin({
      // You need to provide a directory that all the example .vue files will be stored.
      // You can use sub-directories to separate examples into categories.
      componentsPath: '/examples/'
    })
  ],
};
Enter fullscreen mode Exit fullscreen mode

Then inside your .md files you just have to include a vue-example component tag passing to the file prop the filename of your Vue example component (without the .vue extension)

<vue-example file="example" />
Enter fullscreen mode Exit fullscreen mode

That's it!

There's now a section inside your VuePress page, containing the live example and the syntax highlighted contents of the template/script/style SFC tags.

You can check out vuepress-plugin-vue-example here.

Have fun writing docs with VuePress!

Alt Text

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more