You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/time-picker/demo/value.vue

51 lines
916 B

<docs>
---
order: 8
debugger: true
title:
zh-CN: 受控组件
en-US: Under Control
---
## zh-CN
value onChange 需要配合使用也可以直接使用v-model
## en-US
`value` and `@change` should be used together or use v-model.
</docs>
<template>
<a-space direction="vertical">
<p>use value and @change</p>
<a-time-picker :value="value" @change="onChange" />
<p>v-model</p>
<a-time-picker v-model:value="value" />
<p>Do not change</p>
<a-time-picker :value="value2" />
</a-space>
</template>
<script lang="ts">
import dayjs, { Dayjs } from 'dayjs';
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const value = ref<Dayjs>();
const onChange = (time: Dayjs) => {
console.log(time);
value.value = time;
};
return {
value,
value2: ref(dayjs()),
onChange,
};
},
});
</script>