Back to Biomejs

noVueOptionsApi

src/content/docs/linter/rules/no-vue-options-api.mdx

latest15.7 KB
Original Source

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: ## Summary - Rule available since: `v2.3.12` - Diagnostic Category: [`lint/nursery/noVueOptionsApi`](/reference/diagnostics#diagnostic-category) - This rule doesn't have a fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - This rule belongs to the following domains: - [`vue`](/linter/domains#vue) ## How to configure ```json title="biome.json" { "linter": { "rules": { "nursery": { "noVueOptionsApi": "error" } } } }
## Description
Disallow the use of Vue Options API.

Vue 3.6's Vapor Mode does not support the Options API.
Components must use the Composition API (`<script setup>` or `defineComponent` with function signature) instead.

This rule helps prepare codebases for Vapor Mode by detecting Options API
patterns that are incompatible with the new rendering mode.

## Examples

### Invalid

```vue
<script>
export default {
  data() {
    return { count: 0 }
  }
}
</script>
<pre class="language-text"><code class="language-text">code-block.vue:1:16 <a href="https://biomejs.dev/linter/rules/no-vue-options-api">lint/nursery/noVueOptionsApi</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Using the Options API is not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>export default &#123; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> data() &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>3 │ </strong> return &#123; count: 0 &#125; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>4 │ </strong> &#125; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>5 │ </strong>&#125; <strong> │ </strong><strong><span style="color: Tomato;">^</span></strong> <strong>6 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Although the Options API is still supported by Vue, using the Composition API is recommended, and makes it possible to use Vue's Vapor mode for better performance.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Use </span><span style="color: lightgreen;"><strong>&lt;script setup&gt;</strong></span><span style="color: lightgreen;"> or </span><span style="color: lightgreen;"><strong>defineComponent</strong></span><span style="color: lightgreen;"> with a function signature to use the </span><span style="color: lightgreen;"><a href="https://vuejs.org/guide/introduction.html#composition-api">Composition API</a></span><span style="color: lightgreen;"> instead.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit </span><span style="color: lightgreen;"><a href="https://biomejs.dev/linter/#nursery">https://biomejs.dev/linter/#nursery</a></span><span style="color: lightgreen;"> for more information.</span> </code></pre>
vue
<script>
export default {
  methods: {
    increment() {
      this.count++
    }
  }
}
</script>
<pre class="language-text"><code class="language-text">code-block.vue:1:16 <a href="https://biomejs.dev/linter/rules/no-vue-options-api">lint/nursery/noVueOptionsApi</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Using the Options API is not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>export default &#123; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> methods: &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>3 │ </strong> increment() &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>4 │ </strong> this.count++ <strong><span style="color: Tomato;">&gt;</span></strong> <strong>5 │ </strong> &#125; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>6 │ </strong> &#125; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>7 │ </strong>&#125; <strong> │ </strong><strong><span style="color: Tomato;">^</span></strong> <strong>8 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Although the Options API is still supported by Vue, using the Composition API is recommended, and makes it possible to use Vue's Vapor mode for better performance.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Use </span><span style="color: lightgreen;"><strong>&lt;script setup&gt;</strong></span><span style="color: lightgreen;"> or </span><span style="color: lightgreen;"><strong>defineComponent</strong></span><span style="color: lightgreen;"> with a function signature to use the </span><span style="color: lightgreen;"><a href="https://vuejs.org/guide/introduction.html#composition-api">Composition API</a></span><span style="color: lightgreen;"> instead.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit </span><span style="color: lightgreen;"><a href="https://biomejs.dev/linter/#nursery">https://biomejs.dev/linter/#nursery</a></span><span style="color: lightgreen;"> for more information.</span> </code></pre>
vue
<script>
export default {
  computed: {
    doubled() {
      return this.count * 2
    }
  }
}
</script>
<pre class="language-text"><code class="language-text">code-block.vue:1:16 <a href="https://biomejs.dev/linter/rules/no-vue-options-api">lint/nursery/noVueOptionsApi</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Using the Options API is not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>export default &#123; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> computed: &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>3 │ </strong> doubled() &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>4 │ </strong> return this.count &#42; 2 <strong><span style="color: Tomato;">&gt;</span></strong> <strong>5 │ </strong> &#125; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>6 │ </strong> &#125; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>7 │ </strong>&#125; <strong> │ </strong><strong><span style="color: Tomato;">^</span></strong> <strong>8 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Although the Options API is still supported by Vue, using the Composition API is recommended, and makes it possible to use Vue's Vapor mode for better performance.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Use </span><span style="color: lightgreen;"><strong>&lt;script setup&gt;</strong></span><span style="color: lightgreen;"> or </span><span style="color: lightgreen;"><strong>defineComponent</strong></span><span style="color: lightgreen;"> with a function signature to use the </span><span style="color: lightgreen;"><a href="https://vuejs.org/guide/introduction.html#composition-api">Composition API</a></span><span style="color: lightgreen;"> instead.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit </span><span style="color: lightgreen;"><a href="https://biomejs.dev/linter/#nursery">https://biomejs.dev/linter/#nursery</a></span><span style="color: lightgreen;"> for more information.</span> </code></pre>
vue
<script>
export default {
  mounted() {
    console.log('Component mounted')
  }
}
</script>
<pre class="language-text"><code class="language-text">code-block.vue:1:16 <a href="https://biomejs.dev/linter/rules/no-vue-options-api">lint/nursery/noVueOptionsApi</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Using the Options API is not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>export default &#123; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> mounted() &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>3 │ </strong> console.log('Component mounted') <strong><span style="color: Tomato;">&gt;</span></strong> <strong>4 │ </strong> &#125; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>5 │ </strong>&#125; <strong> │ </strong><strong><span style="color: Tomato;">^</span></strong> <strong>6 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Although the Options API is still supported by Vue, using the Composition API is recommended, and makes it possible to use Vue's Vapor mode for better performance.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Use </span><span style="color: lightgreen;"><strong>&lt;script setup&gt;</strong></span><span style="color: lightgreen;"> or </span><span style="color: lightgreen;"><strong>defineComponent</strong></span><span style="color: lightgreen;"> with a function signature to use the </span><span style="color: lightgreen;"><a href="https://vuejs.org/guide/introduction.html#composition-api">Composition API</a></span><span style="color: lightgreen;"> instead.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit </span><span style="color: lightgreen;"><a href="https://biomejs.dev/linter/#nursery">https://biomejs.dev/linter/#nursery</a></span><span style="color: lightgreen;"> for more information.</span> </code></pre>
js
import { defineComponent } from 'vue'

defineComponent({
  name: 'MyComponent',
  data() {
    return { count: 0 }
  }
})
<pre class="language-text"><code class="language-text">code-block.js:3:17 <a href="https://biomejs.dev/linter/rules/no-vue-options-api">lint/nursery/noVueOptionsApi</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">Using the Options API is not allowed.</span> <strong>1 │ </strong>import &#123; defineComponent &#125; from 'vue' <strong>2 │ </strong> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>3 │ </strong>defineComponent(&#123; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>4 │ </strong> name: 'MyComponent', <strong><span style="color: Tomato;">&gt;</span></strong> <strong>5 │ </strong> data() &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>6 │ </strong> return &#123; count: 0 &#125; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>7 │ </strong> &#125; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>8 │ </strong>&#125;) <strong> │ </strong><strong><span style="color: Tomato;">^</span></strong> <strong>9 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Although the Options API is still supported by Vue, using the Composition API is recommended, and makes it possible to use Vue's Vapor mode for better performance.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Use </span><span style="color: lightgreen;"><strong>&lt;script setup&gt;</strong></span><span style="color: lightgreen;"> or </span><span style="color: lightgreen;"><strong>defineComponent</strong></span><span style="color: lightgreen;"> with a function signature to use the </span><span style="color: lightgreen;"><a href="https://vuejs.org/guide/introduction.html#composition-api">Composition API</a></span><span style="color: lightgreen;"> instead.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit </span><span style="color: lightgreen;"><a href="https://biomejs.dev/linter/#nursery">https://biomejs.dev/linter/#nursery</a></span><span style="color: lightgreen;"> for more information.</span> </code></pre>

Valid

vue
<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>
vue
<script setup>
import { ref, computed } from 'vue'

const count = ref(0)
const doubled = computed(() => count.value * 2)
</script>
vue
<script setup>
import { onMounted } from 'vue'

onMounted(() => {
  console.log('Component mounted')
})
</script>
  • useVueVapor: Enforces the use of Vapor mode in Vue components

Resources

</TabItem> </Tabs>