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

UI Components for Vue
Post Reply
tarkhil
Posts: 17
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: 17
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);

daniloalalmeida
Posts: 1
Joined: 03 Jan 2023, 21:03

03 Jan 2023, 21:07

This is still not working. Has anyone made some progress in resolving this?

Seems like the component's method "toggle" has not be identified.

Post Reply

Return to “PrimeVue”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 14 guests