使用vue styleguidist编写组件文档

示例代码地址

vue-styleguidist-demo

安装与基本配置

npm包安装

npm install --save-dev vue-styleguidist

加入styleguide相关命令

package.json

{
   
  "scripts": {
   
    "styleguide": "vue-styleguidist server",
    "styleguide:build": "vue-styleguidist build"
  }
}
  • vue-styleguidist server: 运行开发服务器。
  • vue-styleguidist build:生成静态 HTML 样式指南。
选项 描述
–config 指定配置文件的路径
–open 在默认浏览器中打开 Styleguidist
–verbose 打印调试信息

基本配置

最小配置
// styleguide.config.js
module.exports = {
   
    title: 'Vue Styleguidist 示例',
    components: 'src/components/**/[A-Z]*.vue',
    version: '1.1.1',
    styleguideDir: 'styleguide-dist',
    // 在编辑器的右上角添加一个小按钮,用于将编辑器的内容复制到剪贴板
    copyCodeButton:true,
    // 是否每个章节是一个独立的页面. 默认:false
    pagePerSection: true,
    // props/events/slot的说明默认是展开还是收缩: expand / collapse / hide
    usageMode: 'expand',
    // 左侧导航默认是展开还是收缩: expand / collapse / hide
    tocMode: 'expand',
    // 显示 prop、事件、槽或方法是否来自当前文件或在 mixin 或扩展组件中配置。如果它是外部的,它会显示组件的名称,并在悬停时显示文件的相对路径。
    displayOrigins: true
}
加载和公开组件

默认情况下,Styleguidist加载您的组件并在全局范围内公开它们以供您的示例使用。您可以使用localRegisterComponents来避免全局注册。这仅在其附加ReadMe.md文件或<docs>块中的示例中加载记录的组件。

查找组件

默认情况下,Styleguidist 将使用此glob 模式搜索组件: src/components/**/*.vue

也可自行修改:

module.exports = {
   
  components: 'src/components/**/[A-Z]*.vue'
}

但会忽略测试文件夹__tests__

章节配置

如果不进行额外的配置章节, 那么每个组件会是一个章节

  • name: 章节标题
  • content: 包含概览内容的 Markdown 文件的位置
  • components: glob 模式字符串、组件路径数组或 glob 模式字符串,或返回组件列表或 glob 模式字符串的函数。相同的规则适用于 root components选项
  • sections: 子章节数组(可以嵌套)
  • description: 本章节的简短说明
  • sectionDepth: 单页的子节数,仅在启用pagePerSection 时可用。
  • exampleMode: 代码示例选项卡的初始状态,使用exampleMode
  • usageMode: 道具和方法选项卡的初始状态,使用usageMode
  • ignore: 不应包含在该部分中的字符串/glob 数组。
  • href: 要导航到的 URL,而不是导航到部分内容
  • external: 如果设置,链接将在新窗口中打开
module.exports = {
   
  sections: [
    {
   
      name: 'Introduction',
      content: 'docs/introduction.md'
    },
    {
   
      name: 'Documentation',
      sections: [
        {
   
          name: 'Installation',
          content: 'docs/installation.md',
          description: 'The description for the installation section'
        },
        {
   
          name: 'Configuration',
          content: 'docs/configuration.md'
        },
        {
   
          name: 'Live Demo',
          external: true,
          href: 'http://example.com'</
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,使用Vue3编写文档审核页面可以遵循以下步骤: 1. 安装Vue3和相关依赖 首先需要在项目中安装Vue3和相关依赖,可以通过npm或者yarn进行安装,具体命令如下: ```bash # 使用npm安装 npm install vue@next npm install vue-router@4 npm install axios npm install element-plus # 或者使用yarn安装 yarn add vue@next yarn add vue-router@4 yarn add axios yarn add element-plus ``` 2. 配置路由 在src目录下创建router文件夹,并在该文件夹下创建index.js,配置路由信息,例如: ```javascript import { createRouter, createWebHistory } from 'vue-router' import DocumentList from '../views/DocumentList.vue' import DocumentDetail from '../views/DocumentDetail.vue' const routes = [ { path: '/', name: 'DocumentList', component: DocumentList }, { path: '/document/:id', name: 'DocumentDetail', component: DocumentDetail } ] const router = createRouter({ history: createWebHistory(), routes }) export default router ``` 3. 创建页面组件 在src目录下创建views文件夹,并在该文件夹下创建DocumentList.vue和DocumentDetail.vue两个页面组件,分别用于展示文档列表和文档详情。 DocumentList.vue示例代码: ```html <template> <div> <h1>文档列表</h1> <ul> <li v-for="document in documents" :key="document.id"> <router-link :to="{ name: 'DocumentDetail', params: { id: document.id } }">{{ document.title }}</router-link> </li> </ul> </div> </template> <script> import axios from 'axios' export default { name: 'DocumentList', data() { return { documents: [] } }, mounted() { axios.get('/api/documents') .then(response => { this.documents = response.data }) .catch(error => { console.log(error) }) } } </script> ``` DocumentDetail.vue示例代码: ```html <template> <div> <h1>{{ document.title }}</h1> <p>{{ document.content }}</p> </div> </template> <script> import axios from 'axios' export default { name: 'DocumentDetail', data() { return { document: {} } }, mounted() { axios.get(`/api/documents/${this.$route.params.id}`) .then(response => { this.document = response.data }) .catch(error => { console.log(error) }) } } </script> ``` 4. 创建API接口 在项目中创建一个API接口,用于获取文档列表和文档详情信息,例如: ```javascript const express = require('express') const app = express() const documents = [ { id: 1, title: '文档1', content: '文档1的内容' }, { id: 2, title: '文档2', content: '文档2的内容' }, { id: 3, title: '文档3', content: '文档3的内容' } ] app.get('/api/documents', (req, res) => { res.json(documents) }) app.get('/api/documents/:id', (req, res) => { const id = parseInt(req.params.id) const document = documents.find(doc => doc.id === id) if (document) { res.json(document) } else { res.status(404).json({ message: '文档不存在' }) } }) app.listen(3000, () => { console.log('API server listening on port 3000') }) ``` 5. 在App.vue中引入路由和页面组件 在App.vue中引入路由和页面组件,并使用router-view组件进行路由展示,例如: ```html <template> <div id="app"> <router-view></router-view> </div> </template> <script> import { createApp } from 'vue' import { createRouter } from 'vue-router' import App from './App.vue' import router from './router' createApp(App) .use(createRouter(router)) .mount('#app') </script> ``` 6. 运行项目 使用npm或者yarn运行项目,例如: ```bash # 使用npm运行项目 npm run serve # 或者使用yarn运行项目 yarn serve ``` 以上就是使用Vue3编写文档审核页面的步骤,希望可以帮助到你!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值