解决方案:利用watch监听v-model
<el-date-picker
v-model="searchForm.timeRange"
type="datetimerange"
value-format="yyyy-MM-dd HH:mm"
range-separator="~"
start-placeholder="开场"
end-placeholder="时间">
</el-date-picker>
export default {
data() {
return {
searchForm: {
timeRange: [],
...
},
...
};
},
...
}
watch: {
'searchForm.timeRange': {
deep: true,
handler(newVal) {
if (!newVal) {
this.searchForm.timeRange = [];
}
},
},
...
}
参考文章: