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.

自作でフォーム系のコンポーネントを作るときの最小単位

0
Posted at

はじめに

自作でフォーム系のコンポーネント(input, radio, select)を作るときのメモです。

環境

nuxt 3.9.3
vue 3.4.13

コンポーネント

コンポーネントの実装は以下のようにしています。

<template>
  <input type="text" @input="updateValue" />
</template>

<script setup lang="ts">
interface Props {
  value: string
}
interface Emits {
  (event: 'update:value', value: string): void
}
const props = defineProps<Props>()
const emit = defineEmits<Emits>()
const value = useVModel(props, 'value', emit)

const updateValue = (event: Event) => {
  value.value = (event.target as HTMLInputElement).value 
}
</script>

使う側

<template>
  <div p="12px" flex="~ col" gap="4px" items="start">
    <span>名前</span>
    <AtomsInput v-model:value="name" />
    <span>- {{ name }} -</span>
  </div>
</template>

<script setup lang="ts">
const name = ref<string>('')
</script>

参考

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?