Formatting input type date in vue.js

14,394

use a formatter:

:formatter="format"

Declare how the value should be formatted within this function:

format(value, event) {
    return moment(value).format('YYYY-MM-DD')
}

As an example using the momentjs library.

Share:
14,394
USER
Author by

USER

HELLO

Updated on June 07, 2022

Comments

  • USER
    USER almost 2 years

    I use bootstrap-vue.

    It includes input type date.

    When I write some number, default format is yyyyyy-mm-dd.

    I want to change format yyyyyy-mm-dd to yyyy-mm-dd.

  • USER
    USER about 5 years
    formatter option works after typing all text. if I type 20190314 it returns 201903-14- .
  • Ohgodwhy
    Ohgodwhy about 5 years
    It should not matter the format at which you type. The purpose of using a data library in the formatter is to take an arbitrary string an attempt to convert it to the proper case. If it's not proper, you should display . an error and let the user know.