无法自定义VueDatePicker。

huangapple go评论63阅读模式
英文:

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>
英文:
&lt;template&gt;
    &lt;VueDatePicker v-model=&quot;date&quot; ref=&quot;datepicker&quot; /&gt;
&lt;/template&gt;

&lt;script setup&gt;
import { ref } from &#39;vue&#39;;
const date = ref();
const datepicker = ref(null);

const yourCustomMethod = () =&gt; {
    if (datepicker) {
      // Close the menu programmatically
      datepicker.value.closeMenu()
    }
}
&lt;/script&gt;

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 &#39;@vuepic/vue-datepicker&#39;;
const element = ref&lt;InstanceType&lt;typeof VueDatePicker&gt; | null&gt;(null)

OR

const element = ref(null as unknown as HTMLElement); // ref&lt;HTMLElement&gt;();

huangapple
  • 本文由 发表于 2023年4月19日 16:35:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76052359.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定