|
3 | 3 | - :gear: This rule is included in `"plugin:vue/recommended"`.
|
4 | 4 | - :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
|
5 | 5 |
|
6 |
| -This rule makes sure you keep declared order of properties in components. |
7 |
| - |
8 | 6 | ## :book: Rule Details
|
9 | 7 |
|
| 8 | +This rule makes sure you keep declared order of properties in components. |
10 | 9 | Recommended order of properties can be [found here](https://vuejs.org/v2/style-guide/#Component-instance-options-order-recommended).
|
11 | 10 |
|
12 |
| -Examples of **incorrect** code for this rule: |
13 |
| - |
14 |
| -```js |
15 |
| -name: 'app', |
16 |
| -data () { |
17 |
| - return { |
18 |
| - msg: 'Welcome to Your Vue.js App' |
| 11 | +<eslint-code-block :rules="{'vue/order-in-components': ['error']}"> |
| 12 | +``` |
| 13 | +<script> |
| 14 | +/* ✓ GOOD */ |
| 15 | +export default { |
| 16 | + name: 'app', |
| 17 | + props: { |
| 18 | + propA: Number |
| 19 | + }, |
| 20 | + data () { |
| 21 | + return { |
| 22 | + msg: 'Welcome to Your Vue.js App' |
| 23 | + } |
19 | 24 | }
|
20 |
| -}, |
21 |
| -props: { |
22 |
| - propA: Number, |
23 | 25 | }
|
| 26 | +</script> |
24 | 27 | ```
|
| 28 | +</eslint-code-block> |
25 | 29 |
|
26 |
| -Examples of **correct** code for this rule: |
27 |
| - |
28 |
| -```js |
29 |
| - |
| 30 | +<eslint-code-block :rules="{'vue/order-in-components': ['error']}"> |
| 31 | +``` |
| 32 | +<script> |
| 33 | +/* ✗ BAD */ |
30 | 34 | export default {
|
31 | 35 | name: 'app',
|
32 |
| - props: { |
33 |
| - propA: Number, |
34 |
| - }, |
35 | 36 | data () {
|
36 | 37 | return {
|
37 | 38 | msg: 'Welcome to Your Vue.js App'
|
38 | 39 | }
|
39 | 40 | },
|
| 41 | + props: { |
| 42 | + propA: Number |
| 43 | + } |
40 | 44 | }
|
41 |
| - |
| 45 | +</script> |
42 | 46 | ```
|
43 |
| - |
44 |
| -### Options |
45 |
| - |
46 |
| -If you want you can change the order providing the optional configuration in your `.eslintrc` file. Setting responsible for the above order looks like this: |
47 |
| - |
48 |
| -``` json |
49 |
| -"vue/order-in-components": ["error", { |
50 |
| - "order": [ |
51 |
| - "el", |
52 |
| - "name", |
53 |
| - "parent", |
54 |
| - "functional", |
55 |
| - ["delimiters", "comments"], |
56 |
| - ["components", "directives", "filters"], |
57 |
| - "extends", |
58 |
| - "mixins", |
59 |
| - "inheritAttrs", |
60 |
| - "model", |
61 |
| - ["props", "propsData"], |
62 |
| - "data", |
63 |
| - "computed", |
64 |
| - "watch", |
65 |
| - "LIFECYCLE_HOOKS", |
66 |
| - "methods", |
67 |
| - ["template", "render"], |
68 |
| - "renderError" |
69 |
| - ] |
70 |
| -}] |
| 47 | +</eslint-code-block> |
| 48 | + |
| 49 | +## :wrench: Options |
| 50 | + |
| 51 | +```json |
| 52 | +{ |
| 53 | + "vue/order-in-components": ["error", { |
| 54 | + "order": [ |
| 55 | + "el", |
| 56 | + "name", |
| 57 | + "parent", |
| 58 | + "functional", |
| 59 | + ["delimiters", "comments"], |
| 60 | + ["components", "directives", "filters"], |
| 61 | + "extends", |
| 62 | + "mixins", |
| 63 | + "inheritAttrs", |
| 64 | + "model", |
| 65 | + ["props", "propsData"], |
| 66 | + "data", |
| 67 | + "computed", |
| 68 | + "watch", |
| 69 | + "LIFECYCLE_HOOKS", |
| 70 | + "methods", |
| 71 | + ["template", "render"], |
| 72 | + "renderError" |
| 73 | + ] |
| 74 | + }] |
| 75 | +} |
71 | 76 | ```
|
72 | 77 |
|
73 |
| -If you want some of properties to be treated equally in order you can group them into arrays, like we did with `delimiters` and `comments`. |
| 78 | +- `order` (`(string | string[])[]`) ... The order of properties. Elements are the property names or `LIFECYCLE_HOOKS`. If an element is the array of strings, it means any of those can be placed there unordered. Default is above. |
| 79 | + |
74 | 80 |
|
75 |
| -## Related links |
| 81 | +## :books: Further reading |
76 | 82 |
|
77 | 83 | - [Style guide - Component/instance options order](https://vuejs.org/v2/style-guide/#Component-instance-options-order-recommended)
|
78 | 84 |
|
|
0 commit comments