Skip to content

Instantly share code, notes, and snippets.

@kiranparajuli589
Last active August 4, 2022 12:46
Show Gist options
  • Save kiranparajuli589/f62a23a6fb9b8e219df728fa1396efd5 to your computer and use it in GitHub Desktop.
Save kiranparajuli589/f62a23a6fb9b8e219df728fa1396efd5 to your computer and use it in GitHub Desktop.
TextInput component for Vue3 (Reactive v-model)
<template>
<div class="form-control">
<label class="label">
<span class="label-text">{{ labelName }}</span>
</label>
<input
type="text"
class="input input-bordered"
:value="tv"
@input="updateModelValue"
@focus="focus"
@blur="blur"
>
<span>{{ errorMessage }}</span>
</div>
</template>
<script setup>
import {ref, defineProps, defineEmits} from "vue"
const emit = defineEmits([
"update:modelValue",
"focus",
"blur",
])
const tv = ref("")
defineProps({
labelName: {
type: String,
default: ""
},
errorMessage: {
type: String,
default: ""
}
})
const updateModelValue = ($event) => {
tv.value = $event.target.value
emit("update:modelValue", $event.target.value)
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment