Answer a question

I am trying to captitalize first letter of v-text-field in vuejs but unbale to do. How to do this?

enter image description here

first letter should be auto capital when i am input text like in pic.

Answers

Another way would be to use a watcher. This triggers whenever firstName is changed.

    <template>
      <v-text-field v-model="firstName" label="First Name"></v-text-field>
    </template>
    
    <script>
    export default {
      data() {
        return {
          firstName: "",
        };
      },
      methods: {
        capitalizeFirstLetter: (str) => {
          return str ? str[0].toUpperCase() + str.slice(1) : "";
        },
      },
      watch: {
        firstName: function(newValue) {
          this.firstName = this.capitalizeFirstLetter(newValue);
        },
      },
    };
    </script>
Logo

Vue社区为您提供最前沿的新闻资讯和知识内容

更多推荐