1.
<DatePicker id="startTime" v-on:on-change="getTaxDate" type="month" placement="bottom-start" placeholder="选择日期"></DatePicker> <!-- <input class="timeInput" type="text" id="startTime"> --> <span>—</span> <DatePicker v-on:on-change="getTaxEndDate" type="month" placement="bottom-start" placeholder="选择日期" id="endTime"></DatePicker>
methods: {
getTaxDate: function (date) {
this.startTime = date
},
getTaxEndDate: function (date) {
this.endTime = date
}
}
data () {
return {
id: 'echartsBarType',
id2: 'echartsPieType',
option: {},
option2: {},
startTime: '',
endTime: ''
}
},
watch:{
startTime() {
if (this.startTime) {
console.log('开始时间',this.startTime)
} else {
this.actTaxDate = '';
}
}
}
二:
同时监听两个输入框,如果两个都有值才执行一些方法
用computed
computed: {
timeChange() {
const { startTime, endTime } = this
return {
startTime,
endTime
}
}
},
watch: {
timeChange: {
handler: function(val) {
console.log('address change: ', val)
},
deep: true
}
},