-
-
Notifications
You must be signed in to change notification settings - Fork 202
Open
Description
在我看来真正符合题意的答案
This is the real answer, in my opinion, fits to the question
为 v-model 自定义修饰符,而不是自定义组件或自定义指令
Custom modifiers for 'v-model' instead of custom components or custom directives
<script setup>
import { ref, vModelText } from 'vue'
const _vModelText = vModelText
_vModelText.updated = (el, { value, modifiers: { capitalize } }) => {
if (capitalize && value.hasOwnProperty(0)) {
el.value = value[0].toUpperCase() + value.substr(1)
}
}
const v = ref("")
</script>
<template>
<input type="text" v-model.capitalize="v" />
</template>gastrodia, plus50, iamxiyang, rockfang, aweirdocc and 13 more