Eliminate objects that have been clicked and deleted using the delete button component from the ul list using the filter feature in Vue

I've encountered an issue with Vue.js. Despite trying various methods I found, I'm unable to delete an element. I even consulted a chat GPT for assistance, but unfortunately, the provided answer did not solve my problem.

Below is the code snippet from my homeview.vue file:

//home view from routes component

<template>
    <main class="appMain">
      <Addtodo @addtodo="todos.push($event)"></Addtodo>
      <div class="todo-wrapper">
        <ul class="todo-list">
          <TodoItem v-for="(todo, index) in todos" 
          :key="todo.id"
          :index="index"
          :todo="todo"
          :todos="todos"></TodoItem>
        </ul>
      </div>
    </main>
</template>
...
... // The rest of the template, script, and styles not included for brevity

Additionally, here is a snippet from the todo item file:

<template>
    <li :id="index" class="todo-item-wrapper" :class="{ done: isDone }">
        <div class="todo-item">
            <h2 class="todo-title"> {{ todo.todos.title }} </h2>
            <article class="todo-text"> {{ todo.todos.text }} </article>
            <p class="todo-date"> 
                {{ todo.todos.date | moment }} 
                <span> &nbsp; / &nbsp; </span> 
                {{ todo.todos.time }} 
            </p>
        </div>
        <EditButton :id="index" :isDone="isDone" @updateIsDone="isDone = $event" @deleteItem="deleteControl"/>
    </li>
</template>>
...
... // The rest of the template, script, and styles not included for brevity

Lastly, here is the code snippet for the edit button file:

<template>
...
...

Furthermore, I have a hamburger menu component added in app.vue, not in homeview.vue.

Currently, I am facing issues with implementing filtering and deletion functionality for my to-do items. I have tried using methods like splice, filter, and remove, but they haven't yielded the desired results. I'm open to any suggestions or advice on how to improve my code and make the filtering and deletion functions work as intended.

If anyone has any insights or solutions to my problem, please feel free to share. Thank you.

Answer №1

Here is the code for my to-do list, where I have used an ID to delete an item.

Custom Template

<template>
<div id="todo-list">
    <div id="new-todo-list-item" v-if="location !== 'archive'">
        <input type="text" id="new-todo-list-item-input" placeholder="Enter Todo list.." @keypress="isLetter" @keyup="updateText" v-model="newTodoItem">
        <input type="submit" id="new-todo-list-item-submit" value="Add To Do List Item" @click="newTodolist">
    </div>
    <div class="no-list" v-if="Object.keys(todos).length == 0" >No todo item.</div>
    <div class="list-item" v-for="item in todos" :key="item.id">
        <div class="list-item-holder" v-if="item.location == location" :data-status = "item.completed">
            <input type="checkbox" :data-id="item.id" :id="item.id" :checked="item.completed" @click="updateTodo" :data-status="item.completed"> 
                <label :data-id="item.id" :for="item.id">{{ item.name }}</label>
            <div class="delete-item" @click="deleteTodo" :data-id="item.id">Delete</div>
            <div class="archive-item" :data-id="item.id" v-if="item.location !== 'archive'" @click="moveTodoItem">Archive</div>
        </div>
    </div>
</div>

Invoke State Function

deleteTodo(e) {
   this.$store.commit('deteteTodo', {
      id : e.currentTarget.dataset.id
   });
   this.$notify({ type: "success", text: "Deleted Successfullly." });
 }

JavaScript Logic

deteteTodo(state, todoItem) {
  let id = todoItem.id;

   state.todos.map((data, i) => {
     if (data.id == id) {
         state.todos.splice(i, 1);
      }
    });
  }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dealing with HTML fields that share the same name in various positions can be tricky

Currently, I have developed a non-commercial web application using basic HTML, PHP, and Javascript along with Dynamic Drive's Tab Content code. This app serves as a tool for managing the books in my home library as well as on my ereader. My main goal ...

Is there a way to turn off _moz_resizing on my browser?

I am currently using the nicEdit editor and have successfully integrated my own custom image resizing script. However, I am facing an issue where the default _moz_resizing feature in Firefox is interfering with my custom script. My goal is to have specifi ...

Problems with radio button serialization in jQuery form plugin

I've created a basic form: <form class="dataform" method="post" id="settings" action="/"> <input type="radio" name="shareSetting" value="n"/> <input type="radio" name="shareSetting" value="y"/> <input type="button" na ...

Transforming multi-layered form data into a JSON array structure for seamless integration with application/json

I'm currently developing a Laravel application and facing an issue with the $controller->wantsJson() method in the back-end. This method returns TRUE only if the content type of the request is set to application/json. jQuery.ajax({ type: ...

Implementing the ability to add and remove classes in JavaScript

I am trying to implement an add or remove class feature in JavaScript, but I'm facing some issues with it. Below is the code snippet I have: if (window.location.hash == "#/profile/"){ document.getElementById("tabMenu").removeClass("bottomTa ...

Cookie Multitree: An Innovative JsTree Solution

Hello everyone, I am currently using jstree and have come across a couple of issues with having multiple trees on the same page. Here are my two problems: 1) I am looking to implement cookies to keep track of which nodes are open in each tree. I attempted ...

Reload a single php page by utilizing a different page

Whenever I click on a button on my PHP page (dashboard.php), it opens a pop-up page (viewstatus.php). On this pop-up page, I update some data and then click the submit button. However, after submitting the data, the pop-up should close and the dashboard. ...

Preserve final variable state - Angular

My function looks like this: flag: boolean = false; some_function(){ var foo = some_num_value; var bar = foo; // Storing value in a separate variable if(this.flag){ v ...

Determining the Clicked Button in React When Multiple Buttons are Present

Within my functional component, I have a table with rows that each contain an edit button. However, when I click on one edit button, changes are applied to all of them simultaneously. How can I identify which specific button was clicked and only apply chan ...

Having issues with opening an exported Excel file using ExcelJS

While working on my JS project, I utilized the ExcelJS library. Everything was functioning smoothly with English characters. However, when I switched the language of my application to French and attempted to export the content as an Excel sheet, I encounte ...

What is the best way to ensure that JavaScript is loaded in a specific sequential order?

I'm having trouble ensuring that JS files load in the correct sequence, despite my efforts to research async and defer on various platforms. This is the structure of my code: <script src="lang.js"></script> <!--loading either ...

Tips on sending an Ajax POST request to execute a PHP file

//The code below is found in the inserirPF.js file function add(){ var method = 'AddPerson'; $.ajax({ url: "../class/dao/InserirPFDao.class.php", type: 'POST', data: {Method:method, NAME_:NAME, EMAIL_:EMAIL, PASS ...

Implement a click event for the X-Axis label in Angular 2 Highcharts

I'm currently facing a challenge with hand-rolling a solution that involves adding a click listener to an X-Axis label in a column chart using the HighCharts API within an Angular 2+ application. Here is what I have gathered so far: I am utilizing ...

Error code 12030: AJAX request status

When making an ajax XMLHttpRequest using the POST method, I am encountering a readyState of 4 with a status of 12030. It is known that 12030 is a Microsoft-specific state code indicating that the connection was not sustained. However, I have been unable to ...

The functionality of .map() in Javascript is non-existent

I am completely new to this community (and JavaScript is also new for me), so I apologize in advance for asking some very basic questions. I have an HTML page with various images, all of which share a common class. After using getElementsByClassName, I obt ...

Is there a way to verify if a Backbone.View is actively displayed in the DOM?

Is there a way to determine if a Backbone.View is currently rendered in the DOM, so that I do not need to rerender it? Any suggestions on how this can be achieved? Thanks and regards ...

Is there a way to trigger a 'Are you sure you want to leave this page?' popup in a vue.js router?

I am currently developing a vue.js application and one of our requirements is to display a popup when the user tries to navigate away from a specific page. The popup should prompt the user with a message "Are you sure you want to leave the page?". I am awa ...

Incorporating a protected Grafana dashboard into a web application

I am looking to incorporate Grafana into my web application using AngularJS. The main objective is to allow users to access the Grafana UI by clicking on a button within my application. Setting up an apache reverse proxy for Grafana and ensuring proper COR ...

Triggering a Vue callback once a click method has been successfully executed

Currently, I am dealing with a list containing @click events attached to individual elements. Whenever a user clicks on an element, I am dynamically generating additional elements using v-if. The challenge I am facing is that I need to manipulate these dyn ...

Is it possible to manage how many times a functional react component re-renders based on changes in its state?

For my practice e-commerce app, I have a functional component called "Shop" with two states: [products, setProducts] = useState([10ProductObjects]) and [cart, setCart] = useState([]) Upon the initial render, 10 products are loaded and each Product compone ...