Wang's blog Wang's blog
首页
  • 前端文章

    • HTML教程
    • CSS
    • JavaScript
  • 前端框架

    • Vue
    • React
    • VuePress
    • Electron
  • 后端技术

    • Npm
    • Node
    • TypeScript
  • 编程规范

    • 规范
  • 我的笔记
  • Git
  • GitHub
  • VSCode
  • Mac工具
  • 数据库
  • Google
  • 服务器
  • Python爬虫
  • 前端教程
更多
收藏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Wang Mings

跟随大神,成为大神!
首页
  • 前端文章

    • HTML教程
    • CSS
    • JavaScript
  • 前端框架

    • Vue
    • React
    • VuePress
    • Electron
  • 后端技术

    • Npm
    • Node
    • TypeScript
  • 编程规范

    • 规范
  • 我的笔记
  • Git
  • GitHub
  • VSCode
  • Mac工具
  • 数据库
  • Google
  • 服务器
  • Python爬虫
  • 前端教程
更多
收藏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • Python爬虫

  • 前端教程

    • 团队规范

      • 前端团队规范总结
      • AI前端CSS规范
      • AI前端Git规范
      • AI前端JS规范
      • AI前端Vue规范
      • AI前端工程工具链
      • AI JavaScript 风格指南
      • 推荐-200错误统一处理
      • 推荐-优雅引用字体
      • 推荐-Vue实例选项顺序
      • 组件设计风格
        • 推荐-Vue项目目录结构
        • 推荐-Vue-Router写法
      • Project

      • JS

      • NodeJS

      • Vue

      • React

      • 效率工具

      • 读书笔记

    • 教程
    • 前端教程
    • 团队规范
    wangmings
    2022-07-19
    目录

    组件设计风格

    # # 组件设计风格

    # # 要求 Element 元素统一使用El后缀

        // ✗ bad
        const elem = this.$el;
        const element = e.target;
        const input = this.$refs.input
        
        // ✓ good
        const el = this.$el;
        const el = e.target;
        const inputEl = this.$refs.input;
        
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    # # 要求 Vue 实例统一使用VM后缀

        // ✗ bad
        const instance = this;
        const form = this.$refs.form;
        this.$emit('select', {
            item,
        });
        
        // ✓ good
        const vm = this;
        const formVM = this.$refs.form;
        this.$emit('select', {
            item,
            itemVM: selectedVM,
        });
        
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15

    # # 被动接收事件方法使用on前缀

        // ✗ bad
        {
            methods: {
                input() {
                    // ...
                },
                handleValidate() {
                    // ...
                },
            },
        }
        
        // ✓ good
        {
            methods: {
                onInput() {
                    // ...
                },
                onValidate() {
                    // ...
                },
            },
        }
        
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24

    # # slot 只在对应名称的 class 内设置

        // ✗ bad
        <slot name="head">
            <div :class="$style.head">
                    <slot name="title">
                        <div :class="$style.title">
                            {{ title }}
                        </div>
                    </slot>
                    <div :class="$style.close"></div>
            </div>
        </slot>
        
        // ✓ good
        <div :class="$style.head">
            <slot name="head">
                <div :class="$style.title">
                    <slot name="title">{{ title }}</slot>
                </div>
                <div :class="$style.close"></div>
            </slot>
        </div>
        
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22

    # # 变量命名

    • 常见状态:default, primary, info, success, warning, error, disabled, muted, ...
    • 大小分级:mini, small, base, large, huge, ...
    • 颜色分级:darkest, darker, dark, base, light, lighter, lightest, ...
    编辑 (opens new window)
    推荐-Vue实例选项顺序
    推荐-Vue项目目录结构

    ← 推荐-Vue实例选项顺序 推荐-Vue项目目录结构→

    最近更新
    01
    theme-vdoing-blog博客静态编译问题
    09-16
    02
    搜索引擎
    07-19
    03
    友情链接
    07-19
    更多文章>
    Theme by Vdoing | Copyright © 2019-2022 Evan Xu | MIT License
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式