Skip to content

305 - Capitalize #308

@Thy3634

Description

@Thy3634

在我看来真正符合题意的答案
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>

Vue SFC Playground Link

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions