Javascript Vue.js-无法将日期/时间选择器添加到Vue.js呈现的html元素中
我有一个Vue.js组件,其中有多组文本字段(一组标记为“开始”的文本字段和另一组标记为“到”)绑定到Vue数组(s.timespan) 我想要的是,当我通过向(s.timespans)数组添加元素来添加另一组文本字段时,所有文本字段都会获得日期/时间选择器。但不幸的是,现在只有第一组字段获得日期/时间选择器,而其他组没有。正确的做法是什么 提前谢谢Javascript Vue.js-无法将日期/时间选择器添加到Vue.js呈现的html元素中,javascript,vue.js,vuejs2,vue-component,Javascript,Vue.js,Vuejs2,Vue Component,我有一个Vue.js组件,其中有多组文本字段(一组标记为“开始”的文本字段和另一组标记为“到”)绑定到Vue数组(s.timespan) 我想要的是,当我通过向(s.timespans)数组添加元素来添加另一组文本字段时,所有文本字段都会获得日期/时间选择器。但不幸的是,现在只有第一组字段获得日期/时间选择器,而其他组没有。正确的做法是什么 提前谢谢 <template id="settings"> <div v-for="(k,slot) in s.timespans" cl
<template id="settings">
<div v-for="(k,slot) in s.timespans" class="row mb5">
<div class="col-sm-5">
<label><?php _e( 'From', 'smps' ); ?></label>
<input type="text" class="datepicker form-control" v-model="slot.from">
</div>
<div class="col-sm-5">
<label><?php _e( 'To', 'smps' ); ?></label>
<input type="text" class="datepicker form-control" v-model="slot.to">
</div>
<div class="col-sm-2">
<a href="javascript:" class="btn btn-default pull-right btn-xs br0" @click="remove_timeslot(k)"><i class="fa fa-remove"></i></a>
</div>
</div>
<template>
尝试此操作,然后DOM将完成渲染,而不是在以下时间之前: 执行nextTick中的函数时,将呈现DOM元素
Vue.component( 'settings', {
template : '#settings',
data : function () {
return {
s : {
timespans : [
{from : '', to : ''}
]
}
}
},
methods : {
add_timeslot : function () {
Vue.set(this.s.timespans,this.s.timespans.length,{from:'',to:''});
$('.datepicker').datetimepicker();
},
remove_timeslot : function (k) {
this.s.timespans.splice(k,1);
},
},
});
add_timeslot : function () {
Vue.set(this.s.timespans,this.s.timespans.length,{from:'',to:''});
this.$nextTick(function () {
$('.datepicker').datetimepicker();
});
},