英文:
Unable to customize VueDatePicker
问题
<template>
<VueDatePicker v-model="date" ref="datepicker" />
</template>
<script setup>
import { ref } from 'vue';
const date = ref();
const datepicker = ref(null);
const yourCustomMethod = () => {
if (datepicker) {
// Close the menu programmatically
datepicker.value.closeMenu()
}
}
</script>
英文:
<template>
<VueDatePicker v-model="date" ref="datepicker" />
</template>
<script setup>
import { ref } from 'vue';
const date = ref();
const datepicker = ref(null);
const yourCustomMethod = () => {
if (datepicker) {
// Close the menu programmatically
datepicker.value.closeMenu()
}
}
</script>
I'm trying to customize the VueDatePicker with the implementation mentioned above, but I get an error saying that closeMenu() does not exist in type 'never'. I followed the implementation according to the VueDatePicker documentation, so I can't figure out where the problem is.
I want to solve this issue.
答案1
得分: 1
你可以尝试添加这个条件:
if (datepicker?.value) {
// 关闭菜单
datepicker.value.closeMenu()
}
我在https://codesandbox.io/s/blissful-ully-qg6xpo?file=/src/App.vue 尝试重现了你的问题,但一切正常。
英文:
you can maybe juste add this condition :
if (datepicker?.value) {
// Close the menu programmatically
datepicker.value.closeMenu()
}
I tried to reproduce your problem here https://codesandbox.io/s/blissful-ully-qg6xpo?file=/src/App.vue, but everything works fine
答案2
得分: 0
你可以做类似这样的事情。
import VueDatePicker from '@vuepic/vue-datepicker';
const element = ref<InstanceType<typeof VueDatePicker> | null>(null);
或者
const element = ref(null as unknown as HTMLElement); // ref<HTMLElement>();
英文:
Hey you can do something like this.
import VueDatePicker from '@vuepic/vue-datepicker';
const element = ref<InstanceType<typeof VueDatePicker> | null>(null)
OR
const element = ref(null as unknown as HTMLElement); // ref<HTMLElement>();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论