0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Nuxt3 / Vue3 – defineExpose + ref に型を当てる

Posted at

呼び出し側の記述

refで定義する時に普通に型を当てれば良い

<script setup lang="ts">
type Book = {
  title: string
}

const book = ref<Book>()

</script>

<template>
   <div>{{ book.title }}</div>

  <Book ref="book"/>
</template>

呼びされるComponentの記述例

components/Book.vue

<script lang="ts" setup>
const title = ref('')

defineExpose({
  title,
})
</script>

<template>
  <input v-model="title" />
</template>

参考

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?