环境:
<template>
<div>
<a-date-picker show-time placeholder="Select Time" @change="onChange" @ok="onOk" />
<br />
<a-range-picker
:show-time="{ format: 'HH:mm' }"
format="YYYY-MM-DD HH:mm"
:placeholder="['Start Time', 'End Time']"
@change="onChange"
@ok="onOk"
/>
</div>
</template>
<script>
export default {
methods: {
onChange(value, dateString) {
console.log('Selected Time: ', value);
console.log('Formatted Selected Time: ', dateString);
},
onOk(value) {
console.log('onOk: ', value);
},
},
};
</script>
问题:
如何通过重置按钮清空已选时间控件的值?
解决:
给控件增加v-model,利用双向绑定清空值
<template>
<div>
<a-date-picker show-time placeholder="Select Time" @change="onChange" @ok="onOk" />
<br />
<a-range-picker
v-model="createValue"
:show-time="{ format: 'HH:mm' }"
format="YYYY-MM-DD HH:mm"
:placeholder="['Start Time', 'End Time']"
@change="onChange"
@ok="onOk"
/>
</div>
</template>
<script>
export default {
data() {
return {
createValue:[],
}
},
methods: {
onChange(value, dateString) {
console.log('Selected Time: ', value);
console.log('Formatted Selected Time: ', dateString);
},
onOk(value) {
console.log('onOk: ', value);
},
//重置
reset() {
this.createValue = [];//清空时间控件值
}
},
};
</script>