切换不同的日期选择器,定位错误
日期选择器定位错乱,切换其他的日期,如果是使用v-if来就行切换的话,切换的日期选择器的定位会错乱,变成left:0;top:0
<el-date-picker v-if="selectData === 'consecData'" type="daterange" class="datePicker" start-placeholder="起始日期"
end-placeholder="结束日期" v-model="modeStartDate1" range-separator="至" style="width: 216px; padding-top: 4px" size="mini"
value-format="yyyy-MM-dd" @change="dateChangePush"></el-date-picker>
<el-date-picker v-else-if="selectData === 'consecWeek'" type="daterange" class="datePicker" start-placeholder="起始日期"
end-placeholder="结束日期" v-model="modeStartDate2" range-separator="至" style="width: 216px; padding-top: 4px" size="mini"
value-format="yyyy-MM-dd" @change="weekChangePush"></el-date-picker>
<!-- ="selectData === 'intervalData'" -->
<el-date-picker v-else :disabled="!selectData" type="dates" v-bind:placeholder="placeholder"
v-model="modeStartDate3" style="width: 140px; font-size: 12px" size="mini" value-format="yyyy-MM-dd" @change="handleDateChangePush"></el-date-picker>
实际效果图:
**解决方法:**不要使用v-if来显示隐藏,使用v-show来对日期选择器显示隐藏
<el-date-picker v-show="selectData === 'consecData'" type="daterange" class="datePicker" start-placeholder="起始日期"
end-placeholder="结束日期" v-model="modeStartDate1" range-separator="至" style="width: 216px; padding-top: 4px" size="mini"
value-format="yyyy-MM-dd" @change="dateChangePush"></el-date-picker>
<el-date-picker v-show="selectData === 'consecWeek'" type="daterange" class="datePicker" start-placeholder="起始日期"
end-placeholder="结束日期" v-model="modeStartDate2" range-separator="至" style="width: 216px; padding-top: 4px" size="mini"
value-format="yyyy-MM-dd" @change="weekChangePush"></el-date-picker>
<el-date-picker v-show="selectData === 'intervalData'" :disabled="!selectData" type="dates" v-bind:placeholder="placeholder"
v-model="modeStartDate3" style="width: 140px; font-size: 12px" size="mini" value-format="yyyy-MM-dd" @change="handleDateChangePush"></el-date-picker>
效果图:这样切换的时候定位不会被置为0