linmasahiro / vue3-table-lite

A simple and lightweight data table component for Vue.js 3. Features sorting, paging, row check, dynamic data rendering, supported TypeScript, and more.
https://vue3-lite-table.vercel.app/
MIT License
248 stars 74 forks source link

unwanted multiple event listeners #114

Closed tpzar closed 1 month ago

tpzar commented 3 months ago

Dear @linmasahiro, I have a table, populated from external API, with a searchString input component. Each row has a button to add that element to a database. Every time I update the table after modifying the searchString, a click event listener is added to the button. I see multiple click event listener attached to the same button. How to prevent this?

    const tableLoadingFinish = (elements, localTable) => {
      localTable.isLoading = false;
      Array.prototype.forEach.call(elements, function (element) {
        if (element.classList.contains("add-btn")) {
          element.addEventListener("click", function () {
            event.stopPropagation(); 
            add(this.dataset.id)
          });
        }
      });
    };

    watch(searchName, () => {
      doSearchAdd(0, addtable.limit);
    })

Thank you