primevue-mirror/doc/datepicker/MinMaxDoc.vue

106 lines
3.0 KiB
Vue
Raw Normal View History

2023-02-28 08:29:30 +00:00
<template>
<DocSectionText v-bind="$attrs">
<p>Boundaries for the permitted dates that can be entered are defined with <i>minDate</i> and <i>maxDate</i> properties.</p>
</DocSectionText>
2024-05-20 12:14:38 +00:00
<div class="card flex justify-center">
2024-04-18 14:22:30 +00:00
<DatePicker v-model="date" :minDate="minDate" :maxDate="maxDate" :manualInput="false" />
2023-02-28 08:29:30 +00:00
</div>
<DocSectionCode :code="code" />
</template>
<script>
export default {
data() {
return {
date: null,
minDate: null,
maxDate: null,
code: {
2023-09-22 12:54:14 +00:00
basic: `
2024-04-18 14:22:30 +00:00
<DatePicker v-model="date" :minDate="minDate" :maxDate="maxDate" :manualInput="false" />
2023-10-15 09:38:39 +00:00
`,
2023-09-22 12:54:14 +00:00
options: `
<template>
2024-05-20 12:14:38 +00:00
<div class="card flex justify-center">
2024-04-18 14:22:30 +00:00
<DatePicker v-model="date" :minDate="minDate" :maxDate="maxDate" :manualInput="false" />
2023-02-28 08:29:30 +00:00
</div>
</template>
<script>
export default {
data() {
return {
date: null,
minDate: null,
maxDate: null
};
},
created() {
let today = new Date();
let month = today.getMonth();
let year = today.getFullYear();
let prevMonth = month === 0 ? 11 : month - 1;
let prevYear = prevMonth === 11 ? year - 1 : year;
let nextMonth = month === 11 ? 0 : month + 1;
let nextYear = nextMonth === 0 ? year + 1 : year;
this.minDate = new Date();
this.minDate.setMonth(prevMonth);
this.minDate.setFullYear(prevYear);
this.maxDate = new Date();
this.maxDate.setMonth(nextMonth);
this.maxDate.setFullYear(nextYear);
}
};
2023-10-15 09:38:39 +00:00
<\/script>
`,
2023-09-22 12:54:14 +00:00
composition: `
<template>
2024-05-20 12:14:38 +00:00
<div class="card flex justify-center">
2024-04-18 14:22:30 +00:00
<DatePicker v-model="date" :minDate="minDate" :maxDate="maxDate" :manualInput="false" />
2023-02-28 08:29:30 +00:00
</div>
</template>
<script setup>
import { ref } from "vue";
let today = new Date();
let month = today.getMonth();
let year = today.getFullYear();
let prevMonth = (month === 0) ? 11 : month -1;
let prevYear = (prevMonth === 11) ? year - 1 : year;
let nextMonth = (month === 11) ? 0 : month + 1;
let nextYear = (nextMonth === 0) ? year + 1 : year;
const date = ref();
const minDate = ref(new Date());
const maxDate = ref(new Date());
minDate.value.setMonth(prevMonth);
minDate.value.setFullYear(prevYear);
maxDate.value.setMonth(nextMonth);
maxDate.value.setFullYear(nextYear);
2023-10-15 09:38:39 +00:00
<\/script>
`
2023-02-28 08:29:30 +00:00
}
};
},
created() {
let today = new Date();
let month = today.getMonth();
let year = today.getFullYear();
let prevMonth = month === 0 ? 11 : month - 1;
let prevYear = prevMonth === 11 ? year - 1 : year;
let nextMonth = month === 11 ? 0 : month + 1;
let nextYear = nextMonth === 0 ? year + 1 : year;
this.minDate = new Date();
this.minDate.setMonth(prevMonth);
this.minDate.setFullYear(prevYear);
this.maxDate = new Date();
this.maxDate.setMonth(nextMonth);
this.maxDate.setFullYear(nextYear);
}
};
</script>