yaminncco / vue-sidebar-menu

A Vue.js Sidebar Menu Component
MIT License
646 stars 194 forks source link

Hover event on a single menu item #233

Closed dmtolent closed 2 years ago

dmtolent commented 2 years ago

Hi! Would it be possible to add hover event on a single menu item and access the properties of that menu item object? If not, what would be the best implementation for this? Thanks!

yaminncco commented 2 years ago

Without knowing what you're trying to accomplish, in v5 the attributes property can accept events listeners. a possible solution:

{
  href: '/home',
  title: 'Home',
  attributes: {
    'data-id': 'unique-id',
    onMouseover: (e) => {
      const item = this.menu.find((item) => {
        return item.attributes?.['data-id'] === e.currentTarget.dataset.id
      })
      console.log(item)
    }
  }
}
dmtolent commented 2 years ago

Thanks for the quick response! Is it possible to accommodate this for Vue 2 as well?

yaminncco commented 2 years ago

This specific use-case can be implemented in userland using addEventListener.