vue项目实战系列五:vue书写规范

本文介绍了Vue的官方代码风格指南,强调了组件命名规范(大驼峰、横线),注册组件和prop命名建议,以及编写方法时的顺序,同时鼓励根据实际情况进行适度调整。
摘要由CSDN通过智能技术生成

https://cn.vuejs.org/v2/style-guide/index.html

Style Guide

This is the official style guide for Vue-specific code. If you use Vue in a project, it’s a great reference to avoid errors, bikeshedding, and anti-patterns. However, we don’t believe that any style guide is ideal for all teams or projects, so mindful deviations are encouraged based on past experience, the surrounding tech stack, and personal values.

这里是官方的Vue特有代码的风格指南.如果在工程中使用Vue,为了回避错误、小纠结和反面模式,该指南是份不错的参考.不过,我们也不确信风格指南的所有内容对于所有的团队或工程都是理想的.所以根据过去的经验、周围的技术栈、个人价值观做出有意义的偏差是可取的.

For the most part, we also avoid suggestions about JavaScript or HTML in general. We don’t mind whether you use semicolons or trailing commas. We don’t mind whether your HTML uses single-quotes or double-quotes for attribute values. Some exceptions will exist however, where we’ve found that a particular pattern is helpful in the context of Vue.

对于其绝大部分,我们也总体上避免就JavaScript或HTML的本身提出建议.我们不介意你是否使用分号或结尾的逗号.我们不介意你在HTML attribute中使用单引号还是双引号.不过当我们发现在Vue的情景下有帮助的特定模式时,也会存在例外.


1. 组件命名规范:

(1). 两种:

. 大驼峰:
    MyComponent.vue

②. 横线:
    my-component.vue

(2). 当注册组件或prop时命名风格:

. kebab-case(短横线分隔命名):
    a. 最通用的使用约定

②. camelCase(驼峰式命名). PascalCase(单词首字母大写命名):
    a. 最通用的声明约定

(3). 命名可遵循以下规则:

. 有意义的名词、简短、具有可读性

②. 基础组件名以Base、App命名

③. 文件夹命名主要以功能模块代表命名

(4). Vue组件中的方法书写顺序:

- name
- components
- props
- data
- created
- mounted
- activited
- update
- beforeRouteUpdate
- metods
- filter
- computed
- watch
  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值