【山竹记账前端-vue】8.业务与轮子的关系
大纲链接 §
[toc]
1. 业务与轮子 ⇧
业务开发
- 完成余下的页面
- 在业务中寻找轮子来造
- 学会造轮子,用造轮子的思维看懂业界源码
- 可以基于业界轮子做二次封装满足公司要求
<Button /><FloatButton /><Layout /><Navbar /><Overlay /><Tabs /><EmojiSelect /><Form />
编程的阶段
- 新手学习怎么用轮子(消费者)
- 老手学习怎么造轮子(生产者)
什么样的轮子值得使用
- 至少一个贡献者持续三年以上的
2. 创建 Button 组件 ⇧
@/components/BarButton.tsx
|
|
- 除了
vue自动绑定的class和style属性,需要额外声明组件外部参数的类型XxxProps
在页面中引用,先创建开始记账路由
@/router/routes.ts
|
|
页面组件
@/views/StartAccountsView.tsx
|
|
- 子组件声明好内部的
Props,父组件使用时可以得到明确的类型提示onClick: ...
3. 创建 FloatButton 和 SvgIcon 组件 ⇧
复用已有的 SvgIcon 组件,添加Props类型 ⇧
iconfont给设计师的图标绘制标准
- 图标绘制
- 需要设计师按照标准设计图标,尽量使用矢量图
SVG格式 - 注意下载时,根据是否需要自定义填充色,选择去除填充色,即
svg中所有的fill属性
@/components/icons/SvgIcon.tsx
已单独声明图标名称枚举类型
SvgIconNames1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41import { defineComponent, type PropType } from 'vue' import { cn } from 'cn' import { svgIconNames, type SvgIconNames } from '@/components/icons/svgIconNames.ts' interface SvgIconProps { name: SvgIconNames } /** * @Description: 图标组件 * @Description: 默认使用插件 vite-plugin-svg-icons-ng * @Description: 替换使用插件 svgoStore * @FilePath: content/post/山竹记账/【山竹记账前端-vue】8.业务与轮子的关系.md */ export const SvgIcon = defineComponent<SvgIconProps>({ name: 'SvgIcon', props: { name: { type: String as PropType<SvgIconNames>, required: true, validator: (value: unknown) => typeof value === 'string' && (svgIconNames as readonly string[]).includes(value), }, }, setup(props, _ctx) { // 添加验证 if (!props.name || !(svgIconNames as readonly string[]).includes(props.name)) { console.error(`Invalid icon name: ${props.name}`) } return () => ( <svg class={cn( 'where:(h-1em w-1em align-[-0.15em] fill-[currentColor] overflow-clip)', )} aria-hidden="true"> <use xlinkHref={`#icon-${props.name}`}/> </svg> ) }, })
封装 FloatButton 组件 ⇧
- 添加了一个已去色的图标
add.svg作为按钮图标
@/components/FloatButton.tsx
|
|
在
@/views/StartAccountsView.tsx中使用
|
|
完成 StartAccountsView 页面组件 ⇧
支持
FloatButton.tsx组件图标可自定义修改为项目中已有的图标
|
|
@/views/StartAccountsView.tsx
|
|
继续 Navbar 与 Overlay 组件
4. 制作 Center 组件 ⇧
新增 PlaceCenter 居中布局组件
@/components/icons/PlaceCenter.tsx
|
|
添加居中图标组件
@/views/StartAccountsView.tsx
|
|
5. 制作 Navbar 组件 ⇧
@/components/NavBar.tsx
|
|
@/components/NavBar.module.scss
|
|
@src/views/StartAccountsView.tsx
|
|
- 使用具名插槽传参
icon和头部标题文字
6. 制作 Overlay 组件 ⇧
点击菜单按钮,左侧划出浮层
4. 完善 Overlay 样式 ⇧
·未完待续·
参考文章
相关文章
- 无
- 作者: Joel
- 文章链接:
- 版权声明
- 非自由转载-非商用-非衍生-保持署名