我是靠谱客的博主 傲娇电脑,最近开发中收集的这篇文章主要介绍Vue中 常用的命名规范,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

组件名

官方推荐的组件名是 每个单词首字母大写(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>

props

声明 prop的时候, 使用驼峰命名(myProps), 模板中使用的时候, 用 - 连接(my-props)

 props: {
myProps: {}
}
<my-component :my-props="abc"></my-component>

自定义事件名

因为html对大小写不敏感,所以大写的都会被转为小写的。 所以推荐 都用 -连接来命名。

this.$emit('my-event';
<my-component @my-event="abc"></my-component>

最后

以上就是傲娇电脑为你收集整理的Vue中 常用的命名规范的全部内容,希望文章能够帮你解决Vue中 常用的命名规范所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(91)

评论列表共有 0 条评论

立即
投稿
返回
顶部