Vue ^3.3 introduces a new feature where you can utilize defineOptions()
directly:
<script setup>
defineOptions({
name: 'CustomName',
inheritAttrs: false,
customOptions: {},
})
</script>
The <script setup>
syntax allows you to achieve similar functionality as most existing Options API options, with the exception of a few:
name
inheritAttrs
- Custom options required by plugins or libraries
If you need to specify these options, there are two approaches:
- If utilizing Vue Macros, you can employ
defineOptions()
, which is a concise method:
<script setup>
defineOptions({
name: 'CustomName',
inheritAttrs: false,
customOptions: {},
})
</script>
- If you prefer not to depend on external libraries, you can use a separate regular
<script>
block with export default
:
<script>
export default {
name: 'CustomName',
inheritAttrs: false,
customOptions: {},
}
</script>
<script setup>
// script setup logic
</script>
Compiled output:
<script>
export default {
name: 'CustomName',
inheritAttrs: false,
customOptions: {},
setup() {
// script setup logic
},
}
</script>