Skip to content

Commit 1823583

Browse files
authored
Add Nuxt and Vue Router properties in order-in-components (#1107)
* Add other Nuxt properties * Add Vue Router's navigation guard properties * Update rule docs * Change order according to feedback
1 parent ad70c98 commit 1823583

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

docs/rules/order-in-components.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -65,31 +65,48 @@ export default {
6565
"order": [
6666
"el",
6767
"name",
68+
"key",
6869
"parent",
6970
"functional",
7071
["delimiters", "comments"],
7172
["components", "directives", "filters"],
7273
"extends",
7374
"mixins",
75+
["provide", "inject"],
76+
"ROUTER_GUARDS",
77+
"layout",
78+
"middleware",
79+
"validate",
80+
"scrollToTop",
81+
"transition",
82+
"loading",
7483
"inheritAttrs",
7584
"model",
7685
["props", "propsData"],
86+
"emits",
87+
"setup",
7788
"fetch",
7889
"asyncData",
7990
"data",
91+
"head",
8092
"computed",
8193
"watch",
94+
"watchQuery",
8295
"LIFECYCLE_HOOKS",
8396
"methods",
84-
"head",
8597
["template", "render"],
8698
"renderError"
8799
]
88100
}]
89101
}
90102
```
91103

92-
- `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.
104+
- `order` (`(string | string[])[]`) ... The order of properties. Elements are the property names or one of the following groups:
105+
106+
- `LIFECYCLE_HOOKS`: [Vue Lifecycle Events](https://vuejs.org/v2/guide/instance.html#Lifecycle-Diagram), in the order they are called
107+
- `ROUTER_GUARDS`: [Vue Router Navigation Guards](https://router.vuejs.org/guide/advanced/navigation-guards.html#in-component-guards), in the order they are called
108+
109+
If an element is an array of strings, it means any of those can be placed there unordered. Default is above.
93110

94111

95112
## :books: Further reading

lib/rules/order-in-components.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const defaultOrder = [
1313

1414
// Global Awareness (requires knowledge beyond the component)
1515
'name',
16+
'key', // for Nuxt
1617
'parent',
1718

1819
// Component Type (changes the type of the component)
@@ -29,6 +30,15 @@ const defaultOrder = [
2930
'mixins',
3031
['provide', 'inject'], // for Vue.js 2.2.0+
3132

33+
// Page Options (component rendered as a router page)
34+
'ROUTER_GUARDS', // for Vue Router
35+
'layout', // for Nuxt
36+
'middleware', // for Nuxt
37+
'validate', // for Nuxt
38+
'scrollToTop', // for Nuxt
39+
'transition', // for Nuxt
40+
'loading', // for Nuxt
41+
3242
// Interface (the interface to the component)
3343
'inheritAttrs',
3444
'model',
@@ -45,17 +55,18 @@ const defaultOrder = [
4555
'fetch', // for Nuxt
4656
'asyncData', // for Nuxt
4757
'data',
58+
'head', // for Nuxt
4859
'computed',
4960

5061
// Events (callbacks triggered by reactive events)
5162
'watch',
63+
'watchQuery', // for Nuxt
5264
'LIFECYCLE_HOOKS',
5365

5466
// Non-Reactive Properties (instance properties independent of the reactivity system)
5567
'methods',
5668

5769
// Rendering (the declarative description of the component output)
58-
'head', // for Nuxt
5970
['template', 'render'],
6071
'renderError'
6172
]
@@ -77,6 +88,11 @@ const groups = {
7788
'renderTracked', // for Vue.js 3.x
7889
'renderTriggered', // for Vue.js 3.x
7990
'errorCaptured' // for Vue.js 2.5.0+
91+
],
92+
ROUTER_GUARDS: [
93+
'beforeRouteEnter',
94+
'beforeRouteUpdate',
95+
'beforeRouteLeave'
8096
]
8197
}
8298

0 commit comments

Comments
 (0)