add highlight code component to show demo code
This commit is contained in:
parent
0aa790635a
commit
a7793859c9
|
@ -0,0 +1,45 @@
|
|||
<template>
|
||||
<pre><code class="highlight-code" :ref="ref">
|
||||
<slot></slot>
|
||||
</code></pre>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import 'highlight.js/styles/monokai-sublime.css'
|
||||
|
||||
import highlight from 'highlight.js/lib/highlight'
|
||||
|
||||
import javascript from 'highlight.js/lib/languages/javascript'
|
||||
|
||||
highlight.registerLanguage('javascript', javascript)
|
||||
|
||||
export default {
|
||||
name: 'HighlightCode',
|
||||
data () {
|
||||
return {
|
||||
ref: `highlight-code-${(new Date()).getTime()}`
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
init () {
|
||||
const { ref, $refs } = this
|
||||
|
||||
const codeChunk = $refs[ref]
|
||||
|
||||
highlight.highlightBlock(codeChunk)
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
const { init } = this
|
||||
|
||||
init()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
.highlight-code {
|
||||
font-family: 'code';
|
||||
background-color: transparent;
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue