vue/attributes-order
enforce order of attributes
- ⚙️ This rule is included in all of
"plugin:vue/recommended",*.configs["flat/recommended"],"plugin:vue/vue2-recommended"and*.configs["flat/vue2-recommended"]. - 🔧 The
--fixoption on the command line can automatically fix some of the problems reported by this rule.
📖 Rule Details
This rule aims to enforce ordering of component attributes. The default order is specified in the Vue.js Style Guide and is:
DEFINITIONe.g. 'is', 'v-is'LIST_RENDERINGe.g. 'v-for item in items'CONDITIONALSe.g. 'v-if', 'v-else-if', 'v-else', 'v-show', 'v-cloak'RENDER_MODIFIERSe.g. 'v-once', 'v-pre'GLOBALe.g. 'id'UNIQUEe.g. 'ref', 'key'SLOTe.g. 'v-slot', 'slot'.TWO_WAY_BINDINGe.g. 'v-model'OTHER_DIRECTIVESe.g. 'v-custom-directive'OTHER_ATTRalias for[ATTR_DYNAMIC, ATTR_STATIC, ATTR_SHORTHAND_BOOL]:ATTR_DYNAMICe.g. 'v-bind:prop="foo"', ':prop="foo"'ATTR_STATICe.g. 'prop="foo"', 'custom-prop="foo"'ATTR_SHORTHAND_BOOLe.g. 'boolean-prop'
EVENTSe.g. '@click="functionCall"', 'v-on="event"'CONTENTe.g. 'v-text', 'v-html'
the default order
Note that v-bind="object" syntax is considered to be the same as the next or previous attribute categories.
🔧 Options
json
{
"vue/attributes-order": ["error", {
"order": [
"DEFINITION",
"LIST_RENDERING",
"CONDITIONALS",
"RENDER_MODIFIERS",
"GLOBAL",
["UNIQUE", "SLOT"],
"TWO_WAY_BINDING",
"OTHER_DIRECTIVES",
"OTHER_ATTR",
"EVENTS",
"CONTENT"
],
"alphabetical": false
}]
}"alphabetical": true
Custom orders
['LIST_RENDERING', 'CONDITIONALS', 'RENDER_MODIFIERS', 'GLOBAL', 'UNIQUE', 'TWO_WAY_BINDING', 'DEFINITION', 'OTHER_DIRECTIVES', 'OTHER_ATTR', 'EVENTS', 'CONTENT']
[['LIST_RENDERING', 'CONDITIONALS', 'RENDER_MODIFIERS'], ['DEFINITION', 'GLOBAL', 'UNIQUE'], 'TWO_WAY_BINDING', 'OTHER_DIRECTIVES', 'OTHER_ATTR', 'EVENTS', 'CONTENT']
📚 Further Reading
🚀 Version
This rule was introduced in eslint-plugin-vue v4.3.0