defineNuxtComponent
defineNuxtComponent() 是一个辅助函数,用于使用 Options API 定义类型安全的组件。
defineNuxtComponent() 是一个辅助函数,用于使用类似于 defineComponent() 的选项 API 定义类型安全的 Vue 组件。defineNuxtComponent() 封装器还增加了对 asyncData 和 head 组件选项的支持。在 Nuxt 中,建议使用
<script setup lang="ts"> 声明 Vue 组件。asyncData()
如果你选择不在应用中使用 setup(),则可以在组件定义中使用 asyncData() 方法:
¥If you choose not to use setup() in your app, you can use the asyncData() method within your component definition:
pages/index.vue
<script lang="ts">
export default defineNuxtComponent({
async asyncData() {
return {
data: {
greetings: 'hello world!'
}
}
},
})
</script>
head()
如果你选择不在应用中使用 setup(),则可以在组件定义中使用 head() 方法:
¥If you choose not to use setup() in your app, you can use the head() method within your component definition:
pages/index.vue
<script lang="ts">
export default defineNuxtComponent({
head(nuxtApp) {
return {
title: 'My site'
}
},
})
</script>