简体   繁体   English

无法将 v-model 与 vue-date-picker 绑定

[英]Unable to bind v-model with vue-date-picker

I have used vue-date-picker and v-model for two way data binding.我使用vue-date-pickerv-model进行两种方式的数据绑定。 Initially I have set value to date(ie startDate in this case) and in console I am printing that passed value(ie startDate ).最初我已将值设置为日期(即在这种情况下为startDate ),并且在控制台中我正在打印传递的值(即startDate )。 At first, that passed value to startDate (ie 2019-09-17 is printed) but when I chose new Date, startDate value didn't get updated rather value remained same as it was when it was initially passed.起初,将值传递给 startDate(即打印2019-09-17 ),但是当我选择新日期时,startDate 值没有得到更新,而是值保持与最初传递时的值相同。

       <div class="col-md-3">
            <label for="startDate" class>Start Date</label>
            <datepicker v-model="startDate" :readonly="true" format="YYYY-MM-DD" name="startDate"> 
            </datepicker>
       </div>
       <p>Start Date: {{startDate}}</p>

       <div class="col-md-2">
         <div class="md-form mb-0">
           <button type="button" class="btn btn-primary" @click="showDateValues">Apply</button>
         </div>
       </div>

import datepicker from "vue-date-picker";从“vue-date-picker”导入日期选择器;

<script>
import datepicker from "vue-date-picker";

export default {
  name: "Example",
  components: {
    datepicker
  },
  data() {
    return {
      startDate: "2019-09-17"
    };
  },
  methods:{
    showDateValues(){
      console.log("Start Date: "+this.startDate)
    }
  }
};
</script>

try this:尝试这个:

 data() {
    return {
      startDate: new Date("2019-09-17")
    };
  },

 var elm = new Vue({ el: '.app8', mounted () { var vm = this $('#datedate').datepicker ({ onSelect: function(dateText) { vm.date = dateText } }) });
 <div class="row mt-5"> <div class="col"> <div class="app8"> <input v-model="date" name="date" class="input" type="date" id="datedate"> </div> </div> </div>

Hope this will help希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM