javascript - Vue.js datepicker 不允许更新输入字段的默认值
问题描述
我vue-date-picker
在输入字段中使用日期选择器功能,因为它 100% 符合我的要求。问题是它工作但在加载页面时我从数据库传递了一个默认值。v-model
但在我删除属性之前,它不会向我显示值。
当我删除这个属性时,它没有更新从 datepicker 日历中选择的日期。
这是我正在使用的代码html
<input type="text" id="regular-date" class="form-control w-p100" placeholder="eg. 21 August, 2018" readonly @focus="showRegularDate = true">
<transition name="calendar-fade">
<date-picker color="#b173f8" :format="formatDate"
@close="showRegularDate = false"
v-if="showRegularDate"
v-model="regularDate"></date-picker>
</transition>
在我正在使用的格式的脚本中
<script>
Vue.use(DatePicker)
Vue.config.lang = 'en';
new Vue({
el: '.app',
created: function () {
var today = new Date
this.minDateLimit = '' + today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate()
this.maxDateLimit = '' + today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + (today.getDate() + 7)
},
data: {
regularDate: '',
regularDate_2: '',
regularDate_3: '',
regularDate_4: '',
regularDate_5: '',
showRegularDate: false,
minDateLimit: '',
minDate: '',
showMinDate: false,
maxDateLimit: '',
maxDate: '',
showMaxDate: false,
rangeDate: '',
showRangeDate: false,
specifiedDate: '2016-4-19',
showSpecifiedDate: false,
formattedDate: '',
showFormattedDate: false
},
methods: {
formatDate(date) {
return moment(date).format('LLLL');
},
formatDate_2: function (date) {
return moment(date).format('LLLL');
},
formatDate_3: function (date) {
return moment(date).format('LLLL');
},
formatDate_4: function (date) {
return moment(date).format('LLLL');
},
formatDate_5: function (date) {
return moment(date).format('LLLL');
}
}
})
</script>
我只是将这个 vue 用于datepicker
. 是否有一些我应该做的设置或者我错过了什么?
解决方案
在您的模板中,将日期选择器@close
事件更改为@close="closeDatePickerPopup"
并在您的方法对象中添加以下方法:
closeDatePickerPopup() {
this.showRegularDate = false;
console.log(this.regularDate);
// here you have access to this.regularDate
// and you could do whatever you want with this.regularDate
}
this.regularDate
如果您想要添加此代码段的初始值:
created:function() {
// ------------
},
mounted: function () {
// initialize this.regularDate as follow
this.regularDate = "2018-09-08";
},
推荐阅读
- excel - 使用具有日期条件的先前和当前行值的新熊猫数据框列值
- jgit - 为什么 jGit RemoteAdd 命令不像其他命令那样链接?
- c# - 从 Windows CE 到 Windows Azure 的 https Web API 调用不再有效
- angularjs - calendar.ui/fullCalendar - 营业时间问题
- gnuplot - 频率图最后一个不同宽度的框
- javascript - 如何在应用程序 electron.js 中使用票证 kerberos?
- entity-framework - 如何使用具有多个 dbcontexts 的实体框架迁移,将不同的域类映射到同一个表
- node.js - 从 Http-Server 中的请求中获取 IP 地址
- swift - Swift单按钮处理录音,暂停和恢复
- python - Python在本地包中导入本地包时遇到问题