skip to Main Content
<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.

2

Answers


  1. 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>();
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search