this.$refs.menu.toggle(event); fails with typescript

UI Components for Vue
Post Reply
tarkhil
Posts: 9
Joined: 17 Dec 2020, 21:05

12 Jan 2021, 11:19

Tried to use an example from menu

Code: Select all

<Button type="button" label="Toggle" @click="toggle" />
<Menu ref="menu" :model="items" :popup="true" />


toggle(event) {
    this.$refs.menu.toggle(event);
}
with TypeScript, compilation failed

Code: Select all

37:18 Property 'toggle' does not exist on type 'Vue | Element | Vue[] | Element[]'.
  Property 'toggle' does not exist on type 'Vue'.
    35 | export default class NavBar extends Vue {
    36 |     toggle(event:any) {
  > 37 |        this.$refs.menu.toggle(event);
       |                        ^
    38 |        }

avenmore
Posts: 7
Joined: 09 Nov 2020, 07:03

12 Jan 2021, 12:51

I've found the menu component to have poor type definitions - I hope PrimeTek improve this in the future.

A work-around for now:

Code: Select all

(this.$refs.menu as any).toggle(event);

Post Reply

Return to “PrimeVue”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests