Skip to content

Commit

Permalink
feat: update composition-api-faq.md (#2370)
Browse files Browse the repository at this point in the history
* feat: inheritAttrs in defineOptions

* feat: update composition-api-faq.md

* Apply suggestions from code review

Co-authored-by: Natalia Tepluhina <[email protected]>

---------

Co-authored-by: Natalia Tepluhina <[email protected]>
  • Loading branch information
ikxin and NataliaTepluhina committed Jun 1, 2023
1 parent 1d107b6 commit 0da5428
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/api/options-misc.md
Expand Up @@ -102,6 +102,27 @@ Controls whether the default component attribute fallthrough behavior should be
</template>
```

Since 3.3 you can also use `defineOptions` directly in `<script setup>`:

```vue
<script setup>
defineProps(['label', 'value'])
defineEmits(['input'])
defineOptions({ inheritAttrs: false })
</script>
<template>
<label>
{{ label }}
<input
v-bind="$attrs"
v-bind:value="value"
v-on:input="$emit('input', $event.target.value)"
/>
</label>
</template>
```

</div>

- **See also:** [Fallthrough Attributes](/guide/components/attrs)
Expand Down
11 changes: 11 additions & 0 deletions src/guide/components/attrs.md
Expand Up @@ -92,6 +92,17 @@ export default {
<script setup>
// ...setup logic
</script>
```

Since 3.3 you can also use `defineOptions` directly in `<script setup>`:

```vue
<script setup>
defineOptions({
inheritAttrs: false
})
// ...setup logic
</script>
```

</div>
Expand Down
6 changes: 6 additions & 0 deletions src/guide/extras/composition-api-faq.md
Expand Up @@ -108,6 +108,12 @@ Options API does allow you to "think less" when writing component code, which is

Yes in terms of stateful logic. When using Composition API, there are only a few options that may still be needed: `props`, `emits`, `name`, and `inheritAttrs`. If using `<script setup>`, then `inheritAttrs` is typically the only option that may require a separate normal `<script>` block.

:::tip

Since 3.3 you can directly use `defineOptions` in `<script setup>` to set the component name or `inheritAttrs` property

:::

If you intend to exclusively use Composition API (along with the options listed above), you can shave a few kbs off your production bundle via a [compile-time flag](https://github.com/vuejs/core/tree/main/packages/vue#bundler-build-feature-flags) that drops Options API related code from Vue. Note this also affects Vue components in your dependencies.

### Can I use both APIs together? {#can-i-use-both-apis-together}
Expand Down

0 comments on commit 0da5428

Please sign in to comment.