abstract some component

This commit is contained in:
jiaming
2018-12-17 16:48:46 +08:00
parent 4c2d8e2cdf
commit b553ef8e16
5 changed files with 56 additions and 4 deletions

View File

@ -0,0 +1,52 @@
<template>
<div class="highlight-code">
<pre><code :ref="ref">
<slot></slot>
</code></pre>
</div>
</template>
<script>
import 'highlight.js/styles/monokai-sublime.css'
import highlight from 'highlight.js/lib/highlight'
import xml from 'highlight.js/lib/languages/xml'
import javascript from 'highlight.js/lib/languages/javascript'
highlight.registerLanguage('xml', xml)
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 {
code {
font-family: 'code';
background-color: transparent;
}
}
</style>

8
src/auxiliary/index.js Normal file
View File

@ -0,0 +1,8 @@
import highlightCode from './highlightCode'
import sideNav from './sideNav'
export default function (Vue) {
Vue.component('highlightCode', highlightCode)
Vue.component('sideNav', sideNav)
}

View File

@ -0,0 +1,42 @@
<template>
<div class="side-nav">
<div class="item" v-for="navItem in nav" :key="navItem.title">
<a :href="`#${navItem.target}`">{{ navItem.title }}</a>
</div>
</div>
</template>
<script>
export default {
name: 'SideNav',
props: ['nav']
}
</script>
<style lang="less">
.side-nav {
position: fixed;
width: 150px;
left: 20px;
top: 50%;
transform: translateY(-50%);
.item {
font-weight: bold;
color: #fff;
height: 30px;
line-height: 30px;
font-size: 18px;
a {
color: #fff;
&:hover,
&:active,
&:visited {
color: #fff;
}
}
}
}
</style>