8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VuetifyのDatepickerの値が消えない

Last updated at Posted at 2019-07-09

VuetifyのDatepicker、すごく便利なんだけど、v-text-fieldと一緒に使った時によく使うclearableで値が消えないなーと思っていたメモ。

何したのか

v-text-field@click:clear="date = null"を追加した。

コードは公式サンプルを利用
https://vuetifyjs.com/en/components/date-pickers#date-pickers-formatting-date-using-external-libs

<template>
  <v-menu
    v-model="menu1"
    :close-on-content-click="false"
    full-width
    max-width="290"
  >
    <template v-slot:activator="{ on }">
      <v-text-field
        :value="computedDateFormattedMomentjs"
        clearable
        label="Formatted with Moment.js"
        readonly
        v-on="on"
        @click:clear="date = null" // を追加
      ></v-text-field>
    </template>
    <v-date-picker
      v-model="date"
      @change="menu1 = false"
    ></v-date-picker>
  </v-menu>
</template>

消えなかった理由

v-text-fieldを普通に使ってるだけならclearableオプションを追加するだけでいいけど、他の要素と組み合わせて使う時readonlyをつけてる。多分これが原因。
見た目部分だけは消せるけど、v-modelで紐付けられた値に変更後の値を返さないよーってなってるはず。

以上!

8
8
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?