Last active
August 4, 2022 12:46
-
-
Save kiranparajuli589/f62a23a6fb9b8e219df728fa1396efd5 to your computer and use it in GitHub Desktop.
TextInput component for Vue3 (Reactive v-model)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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