Vue Live Preview
<a href="https://bootstrap-vue.js.org">
<img width="200px" src="https://vuejs.org/images/logo.png">
</a>
<br>
Live preview component for Vue.js and Nuxt.js.
<br>
<br>
<a href="https://vuejs.org">
<img alt="" src="https://img.shields.io/badge/vue.js-2.x-green.svg">
</a>
- 👀 Examples
- 📘 CodeMirror Docs
Installation
```js npm i --save-dev vue-live-preview ```Vue.js
webpack.config.js ```js resolve: { alias: {'vue$': 'vue/dist/vue.esm.js',
}
}
```
main.js
```js
import VueLivePreview from 'vue-live-preview'
import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/material.css';
// CodeMirror options
Vue.use(VueLivePreview, {
theme: 'material',
tabSize: 2,
lineNumbers: true,
})
```
App.vue
```html
```
Nuxt.js
For nuxt, use the component out of server side rendering. nuxt.config.js ```js plugins: { src: '~plugins/vue-live-preview', ssr: false }, , css: 'codemirror/lib/codemirror.css', 'codemirror/theme/material.css', , ``` plugins/vue-live-preview.js ```js import Vue from 'vue' import VueLivePreview from 'vue-live-preview' // CodeMirror options Vue.use(VueLivePreview, { theme: 'material', tabSize: 2, lineNumbers: true, }) ``` Vue.vue ```html<live-preview :code="`Your monofile code here`"></live-preview>
```
Browser
```html<live-preview :code="code"></live-preview>
Import script
```js import VueLivePreview from 'vue-live-preview' import AppComponent from './components/component' import 'codemirror/lib/codemirror.css'; import 'codemirror/theme/material.css'; // CodeMirror options Vue.use(VueLivePreview, { require: {'./components/Component': AppComponent
},
theme: 'material',
tabSize: 2,
lineNumbers: true,
})
```
```html
<template>
<app-component></app-component>
</template>
<script>
import AppComponent from './components/Component'
export default {
components: {
AppComponent
}
}
</script>
`">
```
Or
```html
:code="`
<template>
<app-component></app-component>
</template>
<script>
import AppComponent from './components/Component'
export default {
components: {
AppComponent
}
}
</script>
`">
```