0

我正在使用这个精彩的https://www.creative-tim.com/product/vue-black-dashboard-pro并且他们的组件 Base-Dropdown 具有以下代码:

<template>
  <component :is="tag"
             class="dropdown"
             :class="{show:isOpen}"
             @click="toggleDropDown"
             v-click-outside="closeDropDown">
    <slot name="title-container" :is-open="isOpen">
      <component
        :is="titleTag"
        class="dropdown-toggle btn-rotate"
        :class="titleClasses"
        :aria-expanded="isOpen"
        :aria-label="title || ariaLabel"
        data-toggle="dropdown">
        <slot name="title" :is-open="isOpen">
          <i :class="icon"></i>
          {{title}}
        </slot>
      </component>
    </slot>
    <ul class="dropdown-menu" :class="[{show:isOpen}, {'dropdown-menu-right': menuOnRight}, menuClasses]">
      <slot></slot>
    </ul>
  </component>
</template>
<script>
  export default {
    name: "base-dropdown",
    props: {
      tag: {
        type: String,
        default: "div",
        description: "Dropdown html tag (e.g div, ul etc)"
      },
      titleTag: {
        type: String,
        default: "button",
        description: "Dropdown title (toggle) html tag"
      },
      title: {
        type: String,
        description: "Dropdown title",

      },
      icon: {
        type: String,
        description: "Dropdown icon"
      },
      titleClasses: {
        type: [String, Object, Array],
        description: "Title css classes"
      },
      menuClasses: {
        type: [String, Object],
        description: "Menu css classes"
      },
      menuOnRight: {
        type: Boolean,
        description: "Whether menu should appear on the right"
      },
      ariaLabel: String
    },
    data() {
      return {
        isOpen: false
      };
    },
    methods: {
      toggleDropDown() {
        this.isOpen = !this.isOpen;
        this.$emit("change", this.isOpen);
      },
      closeDropDown() {
        this.isOpen = false;
        this.$emit('change', false);
      }
    }
  };
</script>

现在在另一个组件中,我们称之为“AddAccount.vue”,我正在使用那个 Base-Dropdown 组件,但我似乎无法捕捉到“更改”事件。我已经尝试了一切。

 computed: {
    listeners() {
      return {
        ...this.$listeners,
        change: this.onChange,
      }
    }
  },
  methods: {
    onChange(evt) {
      console.log(":P:")
    },

或者

  computed: {
    change(evt) {
      console.log(":P:")
    }
  },

或者

  methods: {
    change(evt) {
      console.log(":P:")
    },

该组件中没有任何东西被捕获,但是如果我在 Base-Dropdown.vue 中设置断点,它就会被捕获......!

4

0 回答 0