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

推荐-Vue实例选项顺序

# # 推荐-Vue实例选项顺序

在Vue中,export default对象中有很多约定的API Key。每个人的顺序排放都可能不一致,但保持统一的代码风格有助于团队成员多人协作。

Vue官网文档中也有推荐顺序 (opens new window) (opens new window),文档中对选项顺序做了许多分类。但从工程项目角度思考,需要更加精简以及合理的排序。推荐如下规则进行排序:

  1. Vue扩展: extends, mixins, components
  2. Vue数据: props, model, data, computed, watch
  3. Vue资源: filters, directives
  4. Vue生命周期: created, mounted, destroy...
  5. Vue方法: methods

以下推荐顺序,基于团队小伙伴@akimoto整理的顺序:

    export default {
        name: '',
        /*1. Vue扩展 */
        extends: '', // extends和mixins都扩展逻辑,需要重点放前面
        mixins: [],   
        components: {},
        /* 2. Vue数据 */
        props: {},
        model: { prop: '', event: '' }, // model 会使用到 props
        data () {
            return {}
        },
        computed: {},
        watch:{}, // watch 监控的是 props 和 data,有必要时监控computed
        /* 3. Vue资源 */
        filters: {},
        directives: {},
        /* 4. Vue生命周期 */
        created () {},
        mounted () {},
        destroy () {},
        /* 5. Vue方法 */
        methods: {}, // all the methods should be put here in the last
    }
    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
编辑 (opens new window)
推荐-优雅引用字体
组件设计风格

← 推荐-优雅引用字体 组件设计风格→

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