Skip to content

305 - 大写 #2282

Open
Open
@hxg2050

Description

@hxg2050
<script setup>
import { ref, vModelText } from 'vue'
const value = ref("")
vModelText.beforeUpdate = (el, { value, modifiers }) => {
  if (value && modifiers.capitalize) {
    const first = value[0].toLocaleUpperCase();
    if (first !== value[0]) {
      el.value = first + value.slice(1);
      el.setSelectionRange(1, 1);
    }
  }
}
</script>

<template>
  <input type="text" v-model.capitalize="value" />
</template>

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions