diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-03-15 15:02:44 +0000 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2017-03-16 16:08:55 -0500 |
commit | 36e89f977a6a9c649cb9c86bfe76ef6932fdd6a4 (patch) | |
tree | b916130649fe46eafb794d9399219797945b6e4d | |
parent | d524f5c5e51ce6ceed8e130510977c957d5ca83d (diff) | |
download | gitlab-ce-36e89f977a6a9c649cb9c86bfe76ef6932fdd6a4.tar.gz |
Vue js style guide
-rw-r--r-- | doc/development/fe_guide/style_guide.md | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/doc/development/fe_guide/style_guide.md b/doc/development/fe_guide/style_guide.md index 8cd18b9a9aa..4afb31bb237 100644 --- a/doc/development/fe_guide/style_guide.md +++ b/doc/development/fe_guide/style_guide.md @@ -87,6 +87,132 @@ Insert table of contents ``` #### Props +- Props should be declared as an object + ```javascript + // bad + props: ['foo'] + + // good + props: { + foo: { + type: String, + required: false, + default: 'bar' + } + } + ``` +- Required key should always be provided when declaring a prop + ```javascript + // bad + props: { + foo: { + type: String, + } + } + + // good + props: { + foo: { + type: String, + required: false, + default: 'bar' + } + } + ``` + +- Default key should always be provided if the prop is not required: + ```javascript + // bad + props: { + foo: { + type: String, + required: false, + } + } + + // good + props: { + foo: { + type: String, + required: false, + default: 'bar' + } + } + + // good + props: { + foo: { + type: String, + required: true + } + } + ``` + +#### Data +- `data` method should always be a function + ```javascript + // bad + data: { + foo: 'foo' + } + + // good + data() { + return { + foo: 'foo' + }; + } + ``` + +#### Directives + +- Shorthand `@` is preferable over `v-on` + ```javascript + // bad + <component v-on:click="eventHandler"/> + + + // good + <component @click="eventHandler"/> + ``` + +- Shorthand `:` is preferable over `v-bind` + ```javascript + // bad + <component v-bind:class="btn"/> + + + // good + <component :class="btn"/> + ``` + +#### Closing tags +- Prefer self closing component tags + ```javascript + // bad + <component></component> + + // good + <component /> + ``` + +#### Ordering +- Order for a Vue Component: + 1. `props` + 2. `data` + 3. `beforeCreate` + 4. `created` + 5. `beforeMount` + 6. `mounted` + 7. `beforeUpdate` + 8. `updated` + 9. `activated` + 10. `deactivated` + 11. `beforeDestroy` + 12. `destroyed` + 13. `computedProps` + 14. `methods` + 15. `template` ## SCSS |