Here's some contact info
+ +``` + +#### Good + +```html + +``` + +```html + +``` + +```html + +``` + +```html + +``` + +```html + +Here's some contact info
+ +``` + +```html + +Here's some contact info
+ +``` + + +## Priority C Rules: Recommended (Minimizing Arbitrary Choices and Cognitive Overhead) + + +### Component/instance options order (recommended) + +**Component/instance options should be ordered consistently.** + +This is the default order we recommend for component options. They're split into categories, so you'll know where to add new properties from plugins. + +1. **Side Effects** (triggers effects outside the component) + - `el` + +2. **Global Awareness** (requires knowledge beyond the component) + - `name` + - `parent` + +3. **Component Type** (changes the type of the component) + - `functional` + +4. **Template Modifiers** (changes the way templates are compiled) + - `delimiters` + - `comments` + +5. **Template Dependencies** (assets used in the template) + - `components` + - `directives` + - `filters` + +6. **Composition** (merges properties into the options) + - `extends` + - `mixins` + +7. **Interface** (the interface to the component) + - `inheritAttrs` + - `model` + - `props`/`propsData` + +8. **Local State** (local reactive properties) + - `data` + - `computed` + +9. **Events** (callbacks triggered by reactive events) + - `watch` + - Lifecycle Events (in the order they are called) + - `beforeCreate` + - `created` + - `beforeMount` + - `mounted` + - `beforeUpdate` + - `updated` + - `activated` + - `deactivated` + - `beforeDestroy` + - `destroyed` + +10. **Non-Reactive Properties** (instance properties independent of the reactivity system) + - `methods` + +11. **Rendering** (the declarative description of the component output) + - `template`/`render` + - `renderError` + + + +### Element attribute order (recommended) + +**The attributes of elements (including components) should be ordered consistently.** + +This is the default order we recommend for component options. They're split into categories, so you'll know where to add custom attributes and directives. + +1. **Definition** (provides the component options) + - `is` + +2. **List Rendering** (creates multiple variations of the same element) + - `v-for` + +3. **Conditionals** (whether the element is rendered/shown) + - `v-if` + - `v-else-if` + - `v-else` + - `v-show` + - `v-cloak` + +4. **Render Modifiers** (changes the way the element renders) + - `v-pre` + - `v-once` + +5. **Global Awareness** (requires knowledge beyond the component) + - `id` + +6. **Unique Attributes** (attributes that require unique values) + - `ref` + - `key` + - `slot` + +7. **Two-Way Binding** (combining binding and events) + - `v-model` + +8. **Other Attributes** (all unspecified bound & unbound attributes) + +9. **Events** (component event listeners) + - `v-on` + +10. **Content** (overrides the content of the element) + - `v-html` + - `v-text` + + + +### Empty lines in component/instance options (recommended) + +**You may want to add one empty line between multi-line properties, particularly if the options can no longer fit on your screen without scrolling.** + +When components begin to feel cramped or difficult to read, adding spaces between multi-line properties can make them easier to skim again. In some editors, such as Vim, formatting options like this can also make them easier to navigate with the keyboard. + +#### Good + +```js +props: { + value: { + type: String, + required: true + }, + + focused: { + type: Boolean, + default: false + }, + + label: String, + icon: String +}, + +computed: { + formattedValue: function () { + // ... + }, + + inputClasses: function () { + // ... + } +} +``` + +```js +// No spaces are also fine, as long as the component +// is still easy to read and navigate. +props: { + value: { + type: String, + required: true + }, + focused: { + type: Boolean, + default: false + }, + label: String, + icon: String +}, +computed: { + formattedValue: function () { + // ... + }, + inputClasses: function () { + // ... + } +} +``` + + +### Single-file component top-level element order (recommended) + +**[Single-file components](../guide/single-file-components.html) should always order ` +... +``` + +```html + + +... + + + +... + + +``` + +#### Good + +```html + + +... + + + + +... + +``` + +```html + +... + + + + +... + + +``` + + + +## Priority D Rules: Use with Caution (Potentially Dangerous Patterns) + + + +### `v-if`/`v-else-if`/`v-else` without `key` (use with caution) + +**It's usually best to use `key` with `v-if` + `v-else`, if they are the same element type (e.g. both `