Z
Z
z_u_q2022-02-08 00:15:16
Vue.js
z_u_q, 2022-02-08 00:15:16

How to hide non-fitting Vue.js menu items?

I am learning Vue. Wrote a menu script in jQuery. Now I want to rewrite this script in Vue. The menu should always be on one line. If the menu item moves to another line, then the is-hidden class is added. How can I add a method so that a class that doesn't match menu items is added "hidden"? Specifically, it is not clear how to calculate the width of the menu item element and do the calculations that are made in the jQuery script in the menuItems.each(function(i, el) {...});

Link to example (JQuery)

Link to example (Vue)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
grin3671, 2022-02-09
@z_u_q

Start calculations only after the component is added to the page (mounted), otherwise the dimensions of the element will be unknown. Add a variable to calculate the width: in the jQuery example, menuItemsCounter takes on this role. Use this.$refs.menu[index] to calculate the width of each individual element.
Example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question