useVueDefineOptions (JavaScript)
Summary
Section titled “Summary”- Rule available since:
v2.6.4 - Diagnostic Category:
lint/nursery/useVueDefineOptions - This rule doesn’t have a fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
- Sources:
- Same as
vue/prefer-define-options
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useVueDefineOptions": "error" } } }}Description
Section titled “Description”Enforce defineOptions() instead of a default export in components that use <script setup>.
A Vue single-file component can have two script blocks: a plain <script> block and a
<script setup> block. Before Vue 3.3, options such as name or inheritAttrs could
only be set with export default { ... } in the plain <script> block, so the component
was split across both blocks.
Since Vue 3.3, the defineOptions() macro sets these options directly inside
<script setup>. A macro is a function that the Vue compiler handles at build time, so it
doesn’t need to be imported. Using it keeps the whole component in one block.
This rule reports the default export of a plain <script> block when the same file also
has a <script setup> block.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<script>export default { name: "MyComponent", inheritAttrs: false,};</script>
<script setup>const props = defineProps(["title"]);</script>
<script setup>defineOptions({ name: "MyComponent", inheritAttrs: false,});
const props = defineProps(["title"]);</script>A component without <script setup> still uses a default export:
<script>export default { name: "MyComponent",};</script>Resources
Section titled “Resources”Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.