如何使用VuePress搭建一個(gè)類型element ui文檔
網(wǎng)站成果樣式

項(xiàng)目書寫步驟
github地址:https://github.com/xuhuihui/dataCom
官網(wǎng):http://caibaojian.com/vuepress/guide/getting-started.html
參考文章:http://www.dhdzp.com/article/156259.htm
前言:我先git clone官方github,運(yùn)行查看完整效果。 再根據(jù)官網(wǎng)介紹和參考文章,結(jié)合完整的代碼,自己一步步配置內(nèi)容。最后,參考element的設(shè)計(jì)樣式,修改并增加代碼,形成一個(gè)平臺(tái)組件庫(kù)的網(wǎng)站。
(1)在已有項(xiàng)目中安裝
# 安裝為本地依賴項(xiàng)
npm install -D vuepress
# 創(chuàng)建一個(gè) docs 目錄
mkdir docs
# 創(chuàng)建一個(gè) markdown 文件
echo '# Hello VuePress' > docs/README.md
# 給package.json 添加一些 scripts 腳本:{
"scripts": {
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs"
}
}# 運(yùn)行項(xiàng)目
yarn run docs:dev
出現(xiàn)顯示文檔亂碼問題,如圖所示:

解決方式:修改md文件編碼為UTF-8

改變md文件的內(nèi)容如下:
--- home: true actionText: 前往 → actionLink: /baseComponents/ features: - title: 布局類組件 details: 基本組件,為常用組件提供快速,可用的組件 - title: 可視化組件 details: 積累將數(shù)據(jù)可視化的業(yè)務(wù)組件 - title: 知識(shí)庫(kù) details: 積累前端相關(guān)的知識(shí),涵蓋 vue、react、koa2、nodejs 相關(guān)的知識(shí)點(diǎn) ---
(2)配置文件
配置(參考鏈接:http://caibaojian.com/vuepress/config/) VuePress 站點(diǎn)的基本文件是 .vuepress/config.js,其中導(dǎo)出一個(gè) JavaScript 對(duì)象:
module.exports = {
title: 'data Com', // 設(shè)置網(wǎng)站標(biāo)題
description: 'Just for fun', //描述
dest: './dist', // 設(shè)置輸出目錄
port: 2233, //端口
themeConfig: { //主題配置
// 添加導(dǎo)航欄
nav: [
{ text: '主頁(yè)', link: '/' }, // 導(dǎo)航條
{ text: '組件文檔', link: '/baseComponents/' },
{ text: '知識(shí)庫(kù)', link: '/knowledge/' },
{ text: 'github', // 這里是下拉列表展現(xiàn)形式。
items: [
{ text: 'focus-outside', link: 'https://github.com/TaoXuSheng/focus-outside' },
{ text: 'stylus-converter', link: 'https://github.com/TaoXuSheng/stylus-converter' },
]
}
],
// 為以下路由添加側(cè)邊欄
sidebar:{
'/baseComponents/': [
{
title: '布局類組件',
collapsable: true,
children: [
'base/test1',
'base/test2',
'base/test3',
'base/test4',
]
},
{
title: '可視化組件',
collapsable: true,
children: [
]
},
{
title: '工具類組件',
collapsable: true,
children: [
]
},
{
title: '方法類函數(shù)',
collapsable: true,
children: [
]
}
],
'/knowledge/': [
{
title: 'CSS知識(shí)庫(kù)',
collapsable: false,
children: [
]
},
{
title: 'JS知識(shí)庫(kù)',
collapsable: false,
children: [
]
},
{
title: 'node知識(shí)庫(kù)',
collapsable: false,
children: [
]
},
{
title: 'vue知識(shí)庫(kù)',
collapsable: false,
children: [
]
}
]
}
}
}
主題配置部分:在.vuepress/override.styl修改樣式:
$accentColor = #3EB9C8 // 主題色
$textColor = #2c3e50 // 文字顏色
$borderColor = #eaecef // 邊框顏色
$codeBgColor = #282c34 // 代碼背景顏色
// 代碼庫(kù)重置
.content pre{ margin: 0!important;}
(3)增加其它擴(kuò)展插件
插件npm安裝:element-ui,vue-echarts,vue-highlight。。
在.vuepress/enhanceApp.js引入:
/**
* 擴(kuò)展 VuePress 應(yīng)用
*/
import VueHighlightJS from 'vue-highlight.js';
import 'highlight.js/styles/atom-one-dark.css';
import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import VueECharts from 'vue-echarts' //注冊(cè)圖表
import './public/css/index.css' //組件css文件
export default ({
Vue, // VuePress 正在使用的 Vue 構(gòu)造函數(shù)
options, // 附加到根實(shí)例的一些選項(xiàng)
router, // 當(dāng)前應(yīng)用的路由實(shí)例
siteData // 站點(diǎn)元數(shù)據(jù)
}) => {
// ...做一些其他的應(yīng)用級(jí)別的優(yōu)化
Vue.use(VueHighlightJS)
Vue.use(Element)
Vue.component('chart', VueECharts)
}
(4)Markdown 拓展
調(diào)用別人寫好的輪子:https://www.npmjs.com/package/vue-highlight.js
<highlight-code slot="codeText" lang="vue">
<template>
<div class="demo-button">
<div>
<dt-button>默認(rèn)按鈕</dt-button>
<dt-button type="primary">主要按鈕</dt-button>
<dt-button type="success">成功按鈕</dt-button>
<dt-button type="info">信息按鈕</dt-button>
<dt-button type="warning">警告按鈕</dt-button>
<dt-button type="danger">危險(xiǎn)按鈕</dt-button>
</div>
</template>
</highlight-code>
(5)在Markdown 使用Vue-----插入按鈕樣式
#先寫一個(gè)按鈕組件.\vuepress\docs\.vuepress\components\src\button.vue
<template>
<button
class="dt-button"
@click="handleClick"
:disabled="disabled"
:autofocus="autofocus"
:type="nativeType"
:class="[
size ? 'dt-button--' + size : '',
type ? 'dt-button--' + type : '',
{
'is-disabled': disabled,
'is-round': round,
'is-plain': plain
}
]">
<i :class="icon" v-if="icon"></i>
<span v-if="$slots.default"><slot></slot></span>
</button>
</template>
<script>
export default {
name: 'DtButton',
props: {
size: String,
type: {
type: String,
default: 'default'
},
nativeType: {
type: String,
default: 'button'
},
disabled: Boolean,
round: Boolean,
plain: Boolean,
autofocus: Boolean,
icon: {
type: String,
default: ''
}
},
methods: {
handleClick (event) {
this.$emit('click', event)
}
},
mounted () {
this.$emit('click', event)
}
}
</script>
#css樣式,在.\vuepress\docs\.vuepress\public\css\button.css,寫法參考餓了么。
#在.\study\vuepress\docs\.vuepress\public\css\index.css匯總
@import './iconfont.css'; @import './icon.css'; @import './card.css'; @import './button.css'; //按鈕組件 @import './checkbox.css';
#在.\vuepress\docs\.vuepress\components\test\test1.vue文件夾下面調(diào)用button
<template>
<div class="demo-button">
<div>
<dt-button>默認(rèn)按鈕</dt-button>
<dt-button type="primary">主要按鈕</dt-button>
<dt-button type="success">成功按鈕</dt-button>
<dt-button type="info">信息按鈕</dt-button>
<dt-button type="warning">警告按鈕</dt-button>
<dt-button type="danger">危險(xiǎn)按鈕</dt-button>
</div>
</div>
</template>
<script>
import DtButton from '../src/button'
export default {
name: 'buttonWrap',
components: {
DtButton
}
}
</script>
<style lang="less" scoped>
.demo-button{
width: 100%;
text-align: center;
div {
margin: 10px 0;
}
}
</style>
#vuepress會(huì)自動(dòng)根據(jù)路徑注冊(cè)組件,我們只要映射文件路徑,就可以調(diào)用組件。
在.\vuepress\docs\baseComponents\base\test1.md
# 測(cè)試案例1
---
<Common-Democode title="基本用法" description="基本按鈕用法">
<test-test1></test-test1>
<highlight-code slot="codeText" lang="vue">
<template>
<div class="demo-button">
<div>
<dt-button>默認(rèn)按鈕</dt-button>
<dt-button type="primary">主要按鈕</dt-button>
<dt-button type="success">成功按鈕</dt-button>
<dt-button type="info">信息按鈕</dt-button>
<dt-button type="warning">警告按鈕</dt-button>
<dt-button type="danger">危險(xiǎn)按鈕</dt-button>
</div>
</div>
</template>
</highlight-code>
</Common-Democode>
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
#展示效果如圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue router傳遞參數(shù)并解決刷新頁(yè)面參數(shù)丟失問題
這篇文章主要介紹了Vue router傳遞參數(shù)并解決刷新頁(yè)面參數(shù)丟失問題,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12
Vue實(shí)現(xiàn)開始時(shí)間和結(jié)束時(shí)間范圍查詢
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)開始時(shí)間和結(jié)束時(shí)間的范圍查詢,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08
Vuejs實(shí)現(xiàn)帶樣式的單文件組件新方法
這篇文章主要為大家詳細(xì)為大家詳細(xì)介紹了Vuejs實(shí)現(xiàn)帶樣式的單文件組件的新方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05
富文本編輯器vue2-editor實(shí)現(xiàn)全屏功能
這篇文章主要介紹了富文本編輯器vue2-editor實(shí)現(xiàn)全屏功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2019-05-05
Vue +WebSocket + WaveSurferJS 實(shí)現(xiàn)H5聊天對(duì)話交互的實(shí)例
這篇文章主要介紹了Vue +WebSocket + WaveSurferJS 實(shí)現(xiàn)H5聊天對(duì)話交互的實(shí)例,幫助大家更好的理解和學(xué)習(xí)vue,感興趣的朋友可以了解下2020-11-11

