grapoza / vue-tree

Tree components for Vue 3
MIT License
101 stars 12 forks source link

How to listen to events correctly? #290

Closed alimuradov closed 1 year ago

alimuradov commented 1 year ago

Please tell me what I'm doing wrong. When clicking and deleting on elements, handlers are not triggered.

<tree-view
    :initial-model="nodes"
    :model-defaults="modelDefaults"
    @treeViewNodeDelete="treeNodeDelete"
    @treeViewNodeClick="clickCategory"
  >
    <template #text="{ model, customClasses }">
      <div class="flex-row">
        <em
          :title="model.treeNodeSpec.title"
          class="grtvn-self-text mr-2"
          :class="customClasses.treeViewNodeSelfText"
        >
          {{ model[model.treeNodeSpec.labelProperty] }}
        </em>
        <button
          class="ml-2"
          type="button"
          @click="editCategory(model.id)"
        >
          <i class="fa fa-trash"></i>
        </button>
      </div>
    </template>
  </tree-view>
grapoza commented 1 year ago

Hi @alimuradov, it looks like your event names are off. Those are accurate for the 3.x version, but not the 5.x version (you didn't say what version you're using, so I'm assuming latest). For 5.x the event names dropped the View and so are just treeNodeDelete and treeNodeClick. Here's a sample:

https://stackblitz.com/edit/vitejs-vite-hhsauc?file=src%2FApp.vue&terminal=dev

Let me know if you're on 3.x or if this helps with your issue. Also, if you are on 5.x and got your event names from some sample code or docs that need an update from me please let me know that as well!

alimuradov commented 1 year ago

Thank you very much. I did it according to your example and everything worked. I apparently looked at the documentation from the old version.

In my project I use version 5.0

grapoza commented 1 year ago

Great, I'm glad you got it working!