link0 link1 link2 link3 link4 link5 link6 link7 link8 link9 link10 link11 link12 link13 link14 link15 link16 link17 link18 link19 link20 link21 link22 link23 link24 link25 link26 link27 link28 link29 link30 link31 link32 link33 link34 link35 link36 link37 link38 link39 link40 link41 link42 link43 link44 link45 link46 link47 link48 link49 link50 link51 link52 link53 link54 link55 link56 link57 link58 link59 link60 link61 link62 link63 link64 link65 link66 link67 link68 link69 link70 link71 link72 link73 link74 link75 link76 link77 link78 link79 link80 link81 link82 link83 link84 link85 link86 link87 link88 link89 link90 link91 link92 link93 link94 link95 link96 link97 link98 link99 link100 link101 link102 link103 link104 link105 link106 link107 link108 link109 link110 link111 link112 link113 link114 link115 link116 link117 link118 link119 link120 link121 link122 link123 link124 link125 link126 link127 link128 link129 link130 link131 link132 link133 link134 link135 link136

[Vue.js] @click not registering event in Vue devtools

there is a component that is designed to dynamically catch whether a menu item has a submenu attached to it, which it does successfully do. there is set up a method on the instance to toggle whether or not to show the subMenu, but when I click on it, nothing happens. In the vue.js devtools, nothing is registered in the events section. And since the click event isn’t triggered, I’m not getting the expected show/hide toggle.

I’ve tried to follow as closely as I could with the vue.js docs, but despite having the same syntax, I still have no success.

Here is my single file component. The method is called on the two font awesome icons with the @click.

<template>
<div class=”subMenuCatcher”>
<router-link class=”routerLink” active-class=”active” :to=”menuItem.route” exact>
{ menuItem.routeName }
</router-link>
<i
class=”fas fa-arrow-alt-circle-down icon”
:class=”{ hidden: !subMenuHidden }”
@click=”subMenuToggle”
\></i>
<i
class=”fas fa-arrow-alt-circle-up icon”
:class=”{ hidden: subMenuHidden }”
@click=”subMenuToggle”
\></i>
<div
class=”subMenu”
:class=”{ hidden: subMenuHidden }”
v-for=”(subMenuItem, index) in menuItem.subMenu”
:key=”index”
\>
<router-link class=”routerLink” active-class=”active” :to=”subMenuItem.subRoute” exact>
{ subMenuItem.subRouteName }
</router-link>
</div>
</div>
</template>

<script>
const subMenuHidden = true;

export default {
props: {
‘menu-item’: Object,
},
data: function() {
return {
subMenuHidden,
};
},
methods: {
subMenuToggle: function() {
return !this.subMenuHidden;
},
},
};
</script>

<style scoped lang=”scss”>
.subMenuCatcher {
display: flex;
flex-flow: row nowrap;
justify-content: center;
margin: auto;

.subMenu {
display: flex;
flex-flow: column nowrap;
justify-content: center;
}

.routerLink {
text-decoration: none;
color: $routerLinkColor;
}

.active {
color: $activeColor;
}

.icon {
color: $routerLinkColor;
}

.hidden {
display: none;
}
}
</style>

Basically, I’m expecting the subMenuToggle event to fire and change the local state from subMenuHidden = false to true and back. What I’m getting is no event at all.

Solution :

Basically, I’m expecting the subMenuToggle event to fire and change the local state from subMenuHidden = false to true and back. What I’m getting is no event at all.

What you are currently doing is that you are returning the negation of the subMenuHidden value which is false, but nothing happens to the state variable itself.

Change the toggle method to:
this.subMenuHidden = !this.subMenuHidden;