04 - Vue3 UI Framework - 文档页
官网的首页做完了,接下来开始做官网的文档页
返回阅读列表点击 这里
路由设计
先想想我们需要文档页通向哪些地方,这里直接给出我的设计:
| 所属 | 子标题 | 跳转路径 | 文件名(*.vue) |
|---|---|---|---|
| 指南 | 介绍 | /document/introduction | Introduction |
| 指南 | 安装 | /document/install | Install |
| 指南 | 快速上手 | /document/start | Start |
| 组件 | Button | /document/button | Button |
| 组件 | Dialog | /document/dialog | Dialog |
| 组件 | Switch | /document/switch | Switch |
| 组件 | Tabs | /document/tabs | Tabs |
大致就做如上的子内容
然后在 src/components 目录下新建需要的文件们,此处举例 Introduction.vue
<template>
<div>介绍</div>
</template>
<script lang="ts">
export default {
};
</script>
<style lang="scss" scoped>
</style>
再配置 router.ts 以路由
此处使用嵌套路由
// router.ts
import { createWebHistory, createRouter } from 'vue-router'
import Home from './views/Home.vue'
import Document from './views/Document.vue'
import Introduction from './components/Introduction.vue'
import Install from './components/Install.vue'
import Start from './components/Start.vue'
import Button from './components/Button.vue'
import Dialog from './components/Dialog.vue'
import Switch from './components/Switch.vue'
import Tabs from './components/Tabs.vue'
const history = createWebHistory()
const router = createRouter({
history,
routes: [
{ path: '/', component: Home },
{
path: '/document', component: Document, children: [
{ path: '', redirect: '/document/introduction' }, // 默认进入介绍页面
{ path: 'introduction', component: Introduction },
{ path: 'install', component: Install },
{ path: 'start', component: Start },
{ path: 'button', component: Button },
{ path: 'dialog', component: Dialog },
{ path: 'switch', component: Switch },
{ path: 'tabs', component: Tabs },
]
}
]
})
export default router
骨架
然后搭个骨架吧,已知文档页要显示
- 顶边栏
- 菜单
- 内容区域
容易得到如下骨架
<template>
<div class="layout">
<Topnav class="nav" />
<div class="content">
<aside>
<div class="aside-list">
<h2>指南</h2>
<ol>
<li>
<router-link to="/document/introduction">介绍</router-link>
</li>
<li>
<router-link to="/document/introduction">安装</router-link>
</li>
<li>
<router-link to="/document/introduction">快速上手</router-link>
</li>
</ol>
</div>
<div class="aside-list">
<h2>组件列表</h2>
<ol>
<li>
<router-link to="/document/button">Button</router-link>
</li>
<li>
<router-link to="/document/dialog">Dialog</router-link>
</li>
<li>
<router-link to="/document/switch">Switch</router-link>
</li>
<li>
<router-link to="/document/tabs">Tabs</router-link>
</li>
</ol>
</div>
</aside>
<main class="main-body">
<router-view :key="$route.fullPath" />
</main>
</div>
</div>
</template>
然后加上基本的布局样式表
.layout {
display: flex;
flex-direction: column;
height: 100vh;
> .nav {
flex-shrink: 0;
}
> .content {
flex-grow: 1;
padding-top: 90px;
padding-left: 210px;
@media (max-width: 500px) {
padding-left: 0;
}
}
}
.content {
display: flex;
}
侧边栏
重复代码不少,可以优化一下,先在 script 中声明数组:
setup() {
const componentsList = ["Button", "Dialog", "Switch", "Tabs"];
const guidancesList = [
{ path: "introduction", title: "介绍" },
{ path: "install", title: "安装" },
{ path: "start", title: "快速上手" },
];
return {
componentsList,
guidancesList,
};
}
然后在模板中引入
<aside>
<div class="aside-list">
<h2>指南</h2>
<ol>
<li v-for="(guidance, index) in guidancesList" :key="index">
<router-link :to="'/document/' + guidance.path">
{{ guidance.title }}
</router-link>
</li>
</ol>
</div>
<div class="aside-list">
<h2>组件列表</h2>
<ol>
<li v-for="(component, index) in componentsList" :key="index">
<router-link :to="'/document/' + component.toLowerCase()">
{{ component }}
</router-link>
</li>
</ol>
</div>
</aside>
最后补全样式表
<style lang="scss" scoped>
$base-color: #8c6fef;
$aside-index: 10;
$active-color: linear-gradient(
90deg,
rgba(255, 255, 255, 1) 0%,
rgba(255, 255, 255, 1) 97%,
$base-color 97%,
$base-color 100%
);
.layout {
display: flex;
flex-direction: column;
height: 100vh;
> .nav {
flex-shrink: 0;
}
> .content {
flex-grow: 1;
padding-top: 90px;
padding-left: 210px;
@media (max-width: 500px) {
padding-left: 0;
}
}
}
.content {
display: flex;
> aside {
flex-shrink: 0;
width: 200px;
padding: 16px 0;
position: absolute;
top: 0;
left: 0;
padding-top: 90px;
height: 100%;
z-index: $aside-index;
> .aside-list {
margin: 12px 0;
> h2 {
margin-bottom: 4px;
padding: 4px 16px;
}
> ol {
> li {
> a {
display: block;
padding: 8px 32px;
text-decoration: none;
transition: background-color 100ms;
&:hover {
color: $base-color;
background: $active-color;
}
}
.router-link-active {
color: $base-color;
background: $active-color;
}
}
}
}
@media (max-width: 500px) {
background: #8c6fef;
width: 100%;
height: auto;
}
}
> main {
overflow: auto;
flex-grow: 1;
padding: 16px;
background: white;
// border: 1px solid red;
margin-top: 4px;
margin-right: 10px;
@media (max-width: 500px) {
margin-left: 10px;
}
}
}
</style>
就可以做到移动的时候会浮光的侧边栏了。
内容区
先填充一下文档,然后用 border 法调整文本位置,得到如下调整
.content > main {
overflow: auto;
flex-grow: 1;
padding: 16px;
background: white;
margin-top: 4px;
margin-right: 10px;
@media (max-width: 500px) {
margin-left: 10px;
}
}
效果就不贴了,反正只是 padding 的调整
功能
在文档页,还应当可以控制顶边栏上的”弹出菜单”按键的是否可见,显然默认是允许在文档页显示的,所以在模板中调整 Topnav 为
<Topnav toggleMenuButtonVisible class="nav" />
然后获得对菜单的引用
const aside = ref<HTMLDivElement>(null);
<aside v-if="menuVisible" ref="aside"></aside>
再读取 App.vue 提供的 menuVisible,并实现隐藏菜单的方法
const menuVisible = inject<Ref<boolean>>("menuVisible");
const hideMenu = (event) => {
let target: Node = event.target;
if (!(target instanceof HTMLAnchorElement)) {
while (target.parentNode && target.parentNode !== document.body) {
target = target.parentNode;
if (target === aside.value) {
return;
}
}
}
if (document.documentElement.clientWidth <= 500) {
menuVisible.value = false;
}
};
所以有如下 script
import Topnav from "../components/Topnav.vue";
import { inject, ref, Ref } from "vue";
export default {
components: {
Topnav,
},
setup() {
const componentsList = ["Button", "Dialog", "Switch", "Tabs"];
const guidancesList = [
{ path: "introduction", title: "介绍" },
{ path: "install", title: "安装" },
{ path: "start", title: "快速上手" },
];
const aside = ref<HTMLDivElement>(null);
const menuVisible = inject<Ref<boolean>>("menuVisible");
const hideMenu = (event) => {
let target: Node = event.target;
if (!(target instanceof HTMLAnchorElement)) {
while (target.parentNode && target.parentNode !== document.body) {
target = target.parentNode;
if (target === aside.value) {
return;
}
}
}
if (document.documentElement.clientWidth <= 500) {
menuVisible.value = false;
}
};
return {
componentsList,
guidancesList,
aside,
menuVisible,
hideMenu,
};
},
};
取得关闭方法后,通过事件委托,将方法挂载到 div.content 上
<div class="content" @click="hideMenu">
即可实现点击空白处也可以关闭弹出菜单了。
运行效果

感谢阅读
04 - Vue3 UI Framework - 文档页的更多相关文章
- 00 - Vue3 UI Framework - 阅读辅助列表
阅读列表 01 - Vue3 UI Framework - 开始 02 - Vue3 UI Framework - 顶部边栏 03 - Vue3 UI Framework - 首页 04 - Vue3 ...
- 01 - Vue3 UI Framework - 开始
写在前面 一年多没写过博客了,工作.生活逐渐磨平了棱角. 写代码容易,写博客难,坚持写高水平的技术博客更难. 技术控决定慢慢拾起这份坚持,用作技术学习的阶段性总结. 返回阅读列表点击 这里 开始 大前 ...
- 03 - Vue3 UI Framework - 首页
顶部边栏做完了,接下来开始做官网的首页 返回阅读列表点击 这里 创建视图文件夹 让我们先新建一个 src/views 文件夹,用来存放官网的主要视图 然后在该文件夹下新建两个 vue 文件,作为我们的 ...
- 厨娘ui设计文档
厨娘ui设计文档 一.概述 中国的饮食文化从古到今源远流长.在生活日益丰富的今天,人们对饮食的要求不仅仅是温饱,更讲究健康和美味.近年来,饮食甚至成为娱乐的一部分,关于吃的流行用语层出不穷,可见在当今 ...
- Docz 用 MDX 写 React UI 组件文档
Docz 用 MDX 写 React UI 组件文档 前言 为了提升开发效率,创建一套 UI 组件库是一种较为有效的方式之一:可以减少重复工作.提高可复用,所以现在越来越多团队开始创建自己的 UI 组 ...
- 微软Bot Framework文档中,关于Sign-in Card的一处代码错误及更正
Bot Framework文档出错处网址:https://docs.botframework.com/en-us/csharp/builder/sdkreference/attachments.htm ...
- 去除word文档页眉处的横杠
如何去除上图word文档页眉处的横杠 wps软件使用者 第一步双击页眉,到页眉页脚: 第一步点击上图页眉横线,点击无线型或者删除横线即可: Microsoft Office 专业增 ...
- 02 - Vue3 UI Framework - 顶部边栏
顶部边栏比较简单,而且首页和文档页都需要,所以我们先从顶部边栏做起 前文回顾点击 这里 返回阅读列表点击 这里 初始化 首先,在 components 文件夹下,创建一个 vue 组件,命名为 Top ...
- Spring系列(零) Spring Framework 文档中文翻译
Spring 框架文档(核心篇1和2) Version 5.1.3.RELEASE 最新的, 更新的笔记, 支持的版本和其他主题,独立的发布版本等, 是在Github Wiki 项目维护的. 总览 历 ...
随机推荐
- CTF入门学习4->前端HTML基础
Web安全基础 02 前端开发-HTML基础 浏览器对于上网者来说是一种直观.可视化的呈现.服务器发送数据到客户端,客户端需要处理这些数据,互联网就造就了这种数据语言--HTML. 02-00 概述 ...
- [loj3330]猜数游戏
如果两个数$a_{x}$和$a_{y}$,$\exists 0<i,a_{x}^{i}\equiv a_{y}(mod\ p^{k})$,就建一条$x$到$y$的有向边,再对这张图强连通分量缩点 ...
- c语言是如何处理函数调用的?
1. 要编译的测试代码: int plus(int x, int y) { return x + y; } int main(void) { return plus(3, 4); } 2. main ...
- @Inject注解
在看eureka的源码看到了这个注解,百度一下说这个和autowored差不多, import javax.inject.Inject;import javax.inject.Singleton; @ ...
- centos与ubuntu安装及相关问题解答
1.按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别. 答:Linus的发行版本有slackware,debian,redhat,Alpine,ArchLinux,Gentoo,LFS, ...
- CF45G
考虑哥德巴赫猜想:一个偶数可以被拆分两个质数. 所以我们考虑如果不是偶数的话,我们拆分成\((2,m-2)\)或者\((3,del(m - 3))\) 如果是偶数的话\(del(m)\),我们直接枚举 ...
- Can't connect to HTTPS URL because the SSL module is not available. - skipping
今天用pip3安装第三方库的时候报了这样一个错: Can't connect to HTTPS URL because the SSL module is not available. - skipp ...
- 38- Majority Element
Majority Element My Submissions QuestionEditorial Solution Total Accepted: 110538 Total Submissions: ...
- Linux之crond定时任务
1. 使用crontab工具配置的定时任务 2. 配置定时任务建议规范 3. 定时任务配置问题导致系统出现故障实例 1. 使用crontab工具配置的定时任务 名称 crontab - 维护单个用户的 ...
- 【Redis】过期键删除策略和内存淘汰策略
Redis 过期键策略和内存淘汰策略 目录 Redis 过期键策略和内存淘汰策略 设置Redis键过期时间 Redis过期时间的判定 过期键删除策略 定时删除 惰性删除 定期删除 Redis过期删除策 ...