无法自定义VueDatePicker。

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

Unable to customize VueDatePicker

问题

  1. <template>
  2. <VueDatePicker v-model="date" ref="datepicker" />
  3. </template>
  4. <script setup>
  5. import { ref } from 'vue';
  6. const date = ref();
  7. const datepicker = ref(null);
  8. const yourCustomMethod = () => {
  9. if (datepicker) {
  10. // Close the menu programmatically
  11. datepicker.value.closeMenu()
  12. }
  13. }
  14. </script>
英文:
  1. &lt;template&gt;
  2. &lt;VueDatePicker v-model=&quot;date&quot; ref=&quot;datepicker&quot; /&gt;
  3. &lt;/template&gt;
  4. &lt;script setup&gt;
  5. import { ref } from &#39;vue&#39;;
  6. const date = ref();
  7. const datepicker = ref(null);
  8. const yourCustomMethod = () =&gt; {
  9. if (datepicker) {
  10. // Close the menu programmatically
  11. datepicker.value.closeMenu()
  12. }
  13. }
  14. &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

你可以尝试添加这个条件:

  1. if (datepicker?.value) {
  2. // 关闭菜单
  3. datepicker.value.closeMenu()
  4. }

我在https://codesandbox.io/s/blissful-ully-qg6xpo?file=/src/App.vue 尝试重现了你的问题,但一切正常。

英文:

you can maybe juste add this condition :

  1. if (datepicker?.value) {
  2. // Close the menu programmatically
  3. datepicker.value.closeMenu()
  4. }

I tried to reproduce your problem here https://codesandbox.io/s/blissful-ully-qg6xpo?file=/src/App.vue, but everything works fine

答案2

得分: 0

你可以做类似这样的事情。

  1. import VueDatePicker from '@vuepic/vue-datepicker';
  2. const element = ref<InstanceType<typeof VueDatePicker> | null>(null);

或者

  1. const element = ref(null as unknown as HTMLElement); // ref<HTMLElement>();
英文:

Hey you can do something like this.

  1. import VueDatePicker from &#39;@vuepic/vue-datepicker&#39;;
  2. const element = ref&lt;InstanceType&lt;typeof VueDatePicker&gt; | null&gt;(null)

OR

  1. 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:

确定