Vueのコンポーネントの属性の順とタグの順
コンポーネントの属性
コンポーネントの属性の順番が統一されていると作成時に属性の追加や変更が簡単になり、コードも読みやすくなります。
定義されているルールを確認しました。
コンポーネントの属性の順
- Definition (provides the component options)
- is
- List Rendering (creates multiple variations of the same element)
- v-for
- Conditionals (whether the element is rendered/shown)
- v-if
- v-else-if
- v-else
- v-show
- v-cloak
- Render Modifiers (changes the way the element renders)
- v-pre
- v-once
- Global Awareness (requires knowledge beyond the component)
- id
- Unique Attributes (attributes that require unique values)
- ref
- key
- Two-Way Binding (combining binding and events)
- v-model
- Other Attributes (all unspecified bound & unbound attributes)
- Events (component event listeners)
- v-on
- Content (overrides the content of the element)
- v-html
- v-text
コンポーネント内のタグの順
オプションがあるようですが、基本的には下記の順で記載しよう。
- template
- script
- style
リンク
vue/attributes-order
Element attribute order
vue/component-tags-order