如何在datepicker vuetify上添加说明?

时间:2019-10-25 06:11:06

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

我的代码

   <v-dialog
      ref="dialog"
      v-model="modal"
      :return-value.sync="date"
      persistent
      width="290px"

    >
      <template v-slot:activator="{ on }">
        <v-btn color="success" dark v-on="on" @click="test">call datepicker</v-btn>
      </template>
      <v-card :loading="loading">
      <v-date-picker v-model="date" scrollable>
        <v-spacer></v-spacer>
        <v-btn text color="primary" @click="modal = false">Cancel</v-btn>
        <v-btn text color="primary" @click="$refs.dialog.save(date)">OK</v-btn>
      </v-date-picker></v-card>
    </v-dialog>

我的codepen像this

我想添加datepicker可用和不可用的信息,如下所示:

enter image description here

我该怎么办?

3 个答案:

答案 0 :(得分:1)

是的,可以在底部添加文本

可工作的Codepen在这里:https://codepen.io/chansv/pen/gOOLPqp?editors=1010

<div id="app">
  <v-app id="inspire">
    <v-row>
      <v-col cols="12" sm="6" md="4">
        <v-dialog
          ref="dialog"
          v-model="modal"
          :return-value.sync="date"
          persistent
          width="290px"

        >
          <template v-slot:activator="{ on }">
            <v-btn color="success" dark v-on="on" @click="test">call datepicker</v-btn>
          </template>
          <v-card :loading="loading">
          <v-date-picker v-model="date" scrollable>
            <v-spacer></v-spacer>
            <v-btn text color="primary" @click="modal = false">Cancel</v-btn>
            <v-btn text color="primary" @click="$refs.dialog.save(date)">OK</v-btn>
          </v-date-picker></v-card>
        </v-dialog>
      </v-col>

    </v-row>
  </v-app>
</div>

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data: () => ({
    date: new Date().toISOString().substr(0, 10),
    modal: false,
    loading: false,
    footer: false,
  }),

  methods: {
    test () {

      console.log('test')
      this.loading = true;


      var self  = this;
      setTimeout(() =>{
        self.loading = false;
        self.setFooter();
      }
                 , 2000)
    },
    setFooter() {
      if (!this.footer) {
        var div = document.createElement('div');
    var html = "<span><div style='float:left;height: 20px; width: 20px; border-radius: 10px; background-color: green;'></div></span><span style='margin-left: 10px; float: left;'>Available</span><span><div style='float:left;height: 20px; width: 20px; border-radius: 10px; background-color: black; margin-left:10px;'></div></span><span style='margin-left: 10px; float:left;'>Unavailable</span>";
  div.innerHTML = html;
    document.querySelector('.v-date-picker-table').append(div);
        this.footer = true;
      }


    },
  },
})

答案 1 :(得分:0)

您将非常接近这样做,只需在v-date-picker中创建您自己的容器(您必须设置自己的样式以正确放置所有内容)

<v-dialog
    ref="dialog"
    v-model="modal"
    :return-value.sync="date"
    persistent
    width="290px">
    <template v-slot:activator="{ on }">
        <v-btn color="success" dark v-on="on" @click="test">call datepicker</v-btn>
    </template>
    <v-card :loading="loading">
        <v-date-picker v-model="date" scrollable>
            <div>
                <div>Hello</div>
                <v-spacer/>
                <v-btn text color="primary" @click="modal = false">Cancel</v-btn>
                <v-btn text color="primary"
                        @click="$refs.dialog.save(date)">OK</v-btn>
            </div>
        </v-date-picker>
    </v-card>
</v-dialog>

答案 2 :(得分:0)

您还可以在@input上使用v-date-picker,并根据此值更改后可以附加div

您可以在此处查看codepen演示示例。

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data: () => ({
    date: new Date().toISOString().substr(0, 10),
    modal: false,
    loading: false
  }),

  methods: {
    test() {
      console.log('test')
      this.loading = true
      var self = this;
      setTimeout(() => (self.loading = false), 2000)
    },
    onInputValue(val, e) {
      $('div.custom_data_msg').remove();
      $(this.$refs.datepicker.$el).find('div.v-date-picker-table').after(`<div class="custom_data_msg">${val}</div>`);
    }
  },
})
<v-date-picker ref="datepicker" v-on:input="onInputValue($event,event)" v-model="date" scrollable>
  <v-spacer></v-spacer>
  <v-btn text color="primary" @click="modal = false">Cancel</v-btn>
  <v-btn text color="primary" @click="$refs.dialog.save(date)">OK</v-btn>
</v-date-picker>