简体   繁体   English

@click未在Vue devtools中注册事件

[英]@click not registering event in Vue devtools

I have a component that is designed to dynamically catch whether a menu item has a submenu attached to it, which it does successfully do. 我有一个旨在动态捕获菜单项是否具有附加到其的子菜单的组件,该组件确实可以成功完成。 I have set up a method on the instance to toggle whether or not to show the subMenu, but when I click on it, nothing happens. 我已经在实例上设置了一个方法来切换是否显示subMenu,但是当我单击它时,什么也没有发生。 In the Vue devtools, nothing is registered in the events section. 在Vue devtools中,事件部分未注册任何内容。 And since the click event isn't triggered, I'm not getting the expected show/hide toggle. 而且由于未触发click事件,因此无法获得预期的显示/隐藏切换。

I've tried to follow as closely as I could with the Vue docs, but despite having the same syntax, I still have no success. 我已经尽力追随Vue文档,但是尽管语法相同,但仍然没有成功。

Here is my single file component. 这是我的单个文件组件。 The method is called on the two font awesome icons with the @click. 使用@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. 基本上,我期望subMenuToggle事件触发,并将本地状态从subMenuHidden = false更改为true,然后再返回。 What I'm getting is no event at all. 我得到的完全没有任何事件。

Basically, I'm expecting the subMenuToggle event to fire and change the local state from subMenuHidden = false to true and back. 基本上,我期望subMenuToggle事件触发,并将本地状态从subMenuHidden = false更改为true,然后再返回。 What I'm getting is no event at all. 我得到的完全没有任何事件。

What you are currently doing is that you are returning the negation of your subMenuHidden value which is false , but nothing happens to the state variable itself. 您当前正在做的是返回的是false subMenuHidden值的取反,但是状态变量本身未发生任何变化。

Change your toggle method to: this.subMenuHidden = !this.subMenuHidden; 将切换方法更改为: this.subMenuHidden = !this.subMenuHidden;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM