在vuetify中单击按钮时如何显示日期选择器?

时间:2019-10-04 10:28:29

标签: vue.js datepicker vue-component vuetify.js

我的脚本是这样的:

===========-=============================== =======

<template> 
  <v-card
    max-width="1200"
    class="mx-auto"
  >
      <v-row>
        <v-col cols="12" sm="6" md="4">
          <v-menu
            ref="menu"
            v-model="menu"
            :close-on-content-click="false"
            :return-value.sync="date"
            transition="scale-transition"
            offset-y
            min-width="290px"
          >
            <template v-slot:activator="{ on }">
              <v-text-field
                v-model="date"
                label="Picker in menu"
                prepend-icon="event"
                readonly
                v-on="on"
              ></v-text-field>
            </template>
            <v-date-picker v-model="date" no-title scrollable>
              <div class="flex-grow-1"></div>
              <v-btn text color="primary" @click="menu = false">Cancel</v-btn>
              <v-btn text color="primary" @click="$refs.menu.save(date)">OK</v-btn>
            </v-date-picker>
          </v-menu>
        </v-col>
      </v-row>
  </v-card>
</template>
<script>
  export default {
    data: () => ({
      date: new Date().toISOString().substr(0, 10),
      menu: false,
      modal: false,
      menu2: false,
    }),
  }
</script>

结果如下: image1

有效。但我想改变一下。我希望日期选择器在单击这样的按钮时出现: image2

我该怎么办?

1 个答案:

答案 0 :(得分:0)

在您的脚本中,替换

<v-text-field
   v-model="date"
   label="Picker in menu"
   prepend-icon="event"
   readonly
   v-on="on"></v-text-field>

<v-btn v-on="on">CALL DATEPICKER</v-btn>