Vue中 几个常用的命名规范
1,组件名
官方推荐的组件名是 每个单词首字母大写(PascalCase) 或者 全小写用 - 连接(kebab-case) 。 在DOM中使用的时候, 改为全小写, 单词之间用 - 连接。
Vue.component('MyComponent', {}); 或者 Vue.component('my-component', {});
import MyComponent from 'MyComponent.vue'; export default { name: 'MyComponent' } 在DOM中使用的时候, <my-component></my-component>
2,props
声明 prop的时候, 使用驼峰命名(myProps), 模板中使用的时候, 用 - 连接(my-props)
props: {
myProps: {}
}
<my-component :my-props="abc"></my-component>
3,自定义事件名
因为html对大小写不敏感,所以大写的都会被转为小写的。 所以推荐 都用 -连接来命名。
this.$emit('my-event'); <my-component @my-event="abc"></my-component>
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步