父页面
<template>
<DatePicker @child="child" :searchInfo='searchInfo'></DatePicker>
<script>methods
// 接收子组件发送的值
child(data){
if(data.type == 'start') {
this.searchInfo.startTimeStamp = data.timeVal
} else {
this.searchInfo.endTimeStamp = data.timeVal
}
},
子组件<script>methods
定义send方法
// 发送给父组件的方法
send(data){
let params = {
type: data
}
if(data == 'start') {
params.timeVal = this.startTime
this.$emit("child", params)
} else if(data == 'end') {
params.timeVal = this.endTime
this.$emit("child", params)
}
},
调用send方法
onStartTimeChange(startTime, type) {
// console.log(startTime)
this.endTimeOption = {
disabledDate(endTime) {
return (
endTime < new Date(startTime)
);
}
};
this.send('start');
},
onEndTimeChange(endTime, type) {
// console.log(endTime)
this.startTimeOption = {
disabledDate(startTime) {
return (
startTime > new Date(endTime) || startTime > Date.now()
);
}
};
this.send('end');
}