代码:
<el-dialog title="延长到期时间" :visible.sync="delays" width="500px" height="600px" @opened="setDateTimePick">
<div class="panel">
<div class="p-c no-border" style="background:#fff;">
<div class="i">
<div class="tl" style="width: 70%">
<span class="n-i">*</span>
<span>请选择到期时间:</span>
</div>
<div class="tr">
<input class="cin" id="datepicker" autocomplete="off" style="width:90px" type="text"
v-model="searchData.conditions.startTime"/>
</div>
</div>
</div>
<div class="pf">
<button class="btn" >确认修改</button>
</div>
</div>
</el-dialog>
setDateTimePick() {
let that = this
$('#datepicker').datetimepicker({
format: 'Y-m-d', //格式化日期
timepicker: false, //关闭时间选项
yearStart: 1990, //设置最小年份
yearEnd: 2050, //设置最大年份
todayButton: true,
scrollMonth: false,
scrollTime: false,
scrollInput: false,
closeOnInputClick: true
}).on('change', function (picker) {
that.searchData.conditions.startTime = picker.currentTarget.value
})
$.datetimepicker.setLocale('ch')
},
mounted() {
this.setDateTimePick()
},
在Dialog对话框中使用日期组件,因为在页面渲染完之后调用了this.setDateTimePick()方法,而Dialog对话框还没有渲染完毕,所以日期组件出不来,
这个时候就需要改变一下调用方法的时机了,因该在Dialog对话框完全结束之后再去调用日期组件的方法
<el-dialog title="延长到期时间" :visible.sync="delays" width="500px" height="600px" @opened="setDateTimePick">
这样就解决了