SampleView.vue
<script setup>
import { computed, ref } from 'vue';
const content = ref('')
const isValid = computed(() => content.value.length >= 5)
const errorMessage = computed(() => {
if (content.value.length === 0) return ''
return (isValid.value ? '' : '請輸入 5 字以上')
})
</script>
<template>
<input v-model="content" type="text">
<p v-if="errorMessage">{{ errorMessage }}</p>
</template>
<style scoped>
p {
margin: 0;
color: red;
}
</style>

原文出處:https://qiita.com/pomusuke36/items/90697508c14d8f2a5afe