使用vue2修改下述代码,el-date-picker初始值分别为今天0点和明天0点。让el-slider滑块控制el-date-picker的时间,滑块的初始最大最小值为el-date-picker的初始值的getTime(),滑块滑动时与el-date-picker联动。 <div> <el-date-picker v-model="value1" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"> </el-date-picker> <el-slider range style="padding:0 12px;" @change="onChange"></el-slider> </div>
时间: 2024-04-29 16:20:20 浏览: 195
<>
<div>
<el-date-picker
v-model="value1"
type="datetimerange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-value="defaultValue"
:picker-options="pickerOptions"
></el-date-picker>
<el-slider
range
style="padding: 0 12px;"
:min="min"
:max="max"
v-model="sliderValue"
@change="onSliderChange"
></el-slider>
</div>
</template>
<script>
export default {
data() {
return {
value1: [new Date(), new Date(Date.now() + 86400000)],
sliderValue: [new Date().getTime(), new Date(Date.now() + 86400000).getTime()],
pickerOptions: {
selectableRange: '00:00:00 - 23:59:59'
}
}
},
computed: {
min() {
return this.value1[0].getTime()
},
max() {
return this.value1[1].getTime()
},
defaultValue() {
return [new Date(new Date().toLocaleDateString()), new Date(new Date().toLocaleDateString() + ' 23:59:59')]
}
},
methods: {
onSliderChange() {
const [start, end] = this.sliderValue
this.value1 = [new Date(start), new Date(end)]
}
}
}
</script>
阅读全文