首页 > 解决方案 > 在 vue-rangedate-picker (Vuejs) 中清除选定的范围选择器

问题描述

我想通过单击清除按钮清除我的 <VueRangedatePicker @selected="updateDatePicker"> 中的选定日期。但是,当我这样做时。数据已经为空,但显示未清除所选值。有人能帮我吗?谢谢

您可以在此处访问代码:

https://codesandbox.io/s/stoic-sky-3uwch?file=/src/App.vue:0-966

这是代码:

<template>
  <div id="app">
    <VueRangedatePicker @selected="updateDatePicker"></VueRangedatePicker>
    <button class="button" @click="cleardata()">Clear</button>
  </div>
</template>

<script>
import VueRangedatePicker from "vue-rangedate-picker";
export default {
  name: "App",
  components: {
    VueRangedatePicker,
  },
  data() {
    return {
      datepicker: null,
    };
  },
  methods: {
    cleardata() {
      this.datepicker = null;
    },
    updateDatePicker(value) {
      console.log("updating datepicker value");
      this.datepicker = value;

      console.log("DATE PICKER", this.datepicker);
      console.log("start: " + this.datepicker.start);
      console.log("end: " + this.datepicker.end);
    },
  },
};
</script>

<style>
#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

标签: javascriptvue.js

解决方案


我认为您需要取消 2 日期,因为您正在使用日期范围

cleardata() {
      this.datepicker.start = null;
      this.datepicker.end = null;
},

推荐阅读