Menubar: transfer item key parameter in command function

UI Components for Vue
Post Reply
sfranke
Posts: 1
Joined: 14 Mar 2023, 13:03

15 Mar 2023, 12:57

Hallo dear community,
I am a newby in Vue3 and PrimeVue.
I am working on a prototype app with a menubar.
My problem now is, that I am planing to have a general click function for all menubar items.
I will use the key option inside the click function to identify which item was clicked.
But I do not know how to pass this option as input parameter into this function.

This is how I declaired the items array and the click function for the menubar inside the <script> Tag

Code: Select all

    const items = ref([
        { 
            key: 1,
            label: "File",
            command: () => onMenuItemClicked(),
            items: [
                {
                    label: "Open Project",
                    icon: "pi pi-fw pi-file-import"
                },
                {
                    label: "Save Project",
                    icon: "pi pi-fw pi-file-export"
                }
            ]
        },
        
    const onMenuItemClicked = () => {
        console.log("item clicked");
    }
      
The menubar was declaired as follow inside the <template> tag

Code: Select all

 <template>
    <MenuBar v-if="show" :model="items"/>
    
If someone can help me further, I would be very grateful to him.

Thank you very much.

Post Reply

Return to “PrimeVue”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests