使用VuePress搭建在线文档网站

12 篇文章 0 订阅

使用VuePress搭建在线文档网站

在线文档

VuePress官方在线文档(opens new window)

搭建基本环境

# 将 VuePress 作为一个本地依赖安装
npm install -D vuepress

# 新建一个 docs 文件夹
mkdir docs

# 新建一个文件: docs/README.md
echo '# Hello VuePress!' > docs/README.md

# 启动文档项目
npx vuepress dev docs

# 构建静态文件
npx vuepress build docs
  |-- docs
    |-- .vuepress
      |-- config.js
    |-- README.md

配置ts教程文档

  1. 整体结构
|-- dist
|-- dics
  |-- .vuepress
    |-- public
      |-- ts-logo.png
    |-- config.js
  |-- chapter1
    |-- 01_初识TS.md
    |-- 02_安装TS.md
    |-- 03_HelloWorld.md
  |-- chapter2
    |-- 1_type.md
    |-- 2_interface.md
    |-- 3_class.md
    |-- 4_function.md
    |-- 5_generic.md
    |-- 6_other.md
  |-- chapter3
    |-- 01_react.md
    |-- 02_vue.md
  |-- chapter4
    |-- README.md
  |-- README.md
|-- package.json
  1. docs/.vuepress/config.js
// 注意: base的值为github仓库的名称
module.exports = {
  base: '/ts-study/', /* 基础虚拟路径: */
  dest: 'dist', /* 打包文件基础路径, 在命令所在目录下 */
  title: 'TypeScript 入门', // 标题
  description: '学习使用 TypeScript', // 标题下的描述
  themeConfig: { // 主题配置
    sidebar: [ // 左侧导航
      {
        title: '初识 TypeScript', // 标题
        collapsable: false, // 下级列表不可折叠
        children: [ // 下级列表
          'chapter1/01_初识TS',
          'chapter1/02_安装TS',
          'chapter1/03_HelloWorld'
        ]
      },
      {
        title: 'TypeScript 常用语法',
        collapsable: false,
        children: [
          'chapter2/1_type',
          'chapter2/2_interface',
          'chapter2/3_class',
          'chapter2/4_function',
          'chapter2/5_generic',
        ]
      },
    ]
  }
}
  1. docs/README.md
---
#首页
home: true  
# 图标
heroImage: /ts-logo.png
# 按钮文本
actionText: 开始学习 →
# 按钮点击跳转路径
actionLink: /chapter1/01_初识TS
---
  1. package.json
"scripts": {
  "doc:dev": "vuepress dev docs",
  "doc:build": "vuepress build docs",
  "doc:deploy": "gh-pages -d docs/dist"
}

发布到gitpage

  1. 使用git管理当前项目
  2. 将打包的项目推送到gitpage
# 下载工具包
yarn add -D gh-pages
# 执行打包命令
yarn doc:build
# 执行部署命令
yarn doc:deploy
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你想在 Vue 中实现按钮跳转到新页面,可以使用 Vue Router。首先,你需要安装 Vue Router: ``` npm install vue-router ``` 接着,在你的 Vue 实例中引入 Vue Router 并注册路由: ```javascript import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter) const routes = [ { path: '/new-page', name: 'NewPage', component: () => import('@/views/NewPage.vue') } ] const router = new VueRouter({ mode: 'history', routes }) export default router ``` 这里定义了一个路由,当访问 `/new-page` 时,会渲染 `NewPage.vue` 组件。 然后,在你的按钮组件中使用 `router-link` 标签: ```html <template> <router-link to="/new-page">跳转到新页面</router-link> </template> ``` 这样,点击按钮就会跳转到 `/new-page` 页面。 如果你想使用 VuePress 搭建一个 Vue 风格的技术文档/博客,可以参考 VuePress 官方文档中的教程:[VuePress](https://vuepress.vuejs.org/)。首先,你需要安装 VuePress: ``` npm install -D vuepress ``` 然后,在你的项目中创建一个 `.vuepress` 目录,并在其中创建一个 `config.js` 文件: ```javascript module.exports = { title: 'My Blog', description: 'My awesome blog built with VuePress', themeConfig: { nav: [ { text: 'Home', link: '/' }, { text: 'Guide', link: '/guide/' }, { text: 'About', link: '/about/' } ], sidebar: [ '/', '/guide/', '/about/' ] } } ``` 这里定义了站点的标题、描述、导航栏和侧边栏。接着,在 `.vuepress` 目录中创建一个 `README.md` 文件作为首页,以及其他的 Markdown 文件作为文章。 最后,你可以使用以下命令启动 VuePress: ``` npx vuepress dev ``` 这样,你就可以在浏览器中访问你的博客了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值