A
A
Anton Vorobiev2020-10-15 15:13:12
Vue.js
Anton Vorobiev, 2020-10-15 15:13:12

How to delete an item via a confirm button?

5f883733218f5801164293.png
Create.vue - page for creating a contract and saving data in localStorage
List.vue - displaying the value from localStorage to a table via Contact.vue - displaying contact information
v-for="" :key="contact.id"


  • on button click implement deletion of specific table row (from localStorage ) (with confirmation)
  • with the possibility of reverse action.

I'm just starting to learn Vue, so if possible, in more detail in which files what should I write.
source code:
https://github.com/Antoxa291/Contact-book-Vue.js-.git

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Borutkin, 2020-10-15
@Antoxins

The button handles the click - the id of the clicked element is passed to the function.
the function through find looks for the entry = id to the user who came to click on the button.
deleting an entry via splice or delete
"I'm just learning" is not a reason for others to do everything for you

A
Anton Vorobiev, 2020-10-15
@Antoxins

contacts is not defined - error in console
Method in List.vue:

methods: {
        deleteСontact(index) {
            const Index = contacts.findIndex(t => t.id === id)
            this.$delete(this.contacts, Index)
        }
    },

Registered in store.js
actions: { 
deleteContact({commit}, id) {
      commit('deleteContact', id)
    },
}

and
mutations: { 
deleteСontact(state, id) {          
      const idx = contacts.findIndex(t => t.id === id);        
      localStorage.removeItem(state.contacts[idx])
    },
}

Tell me what am I doing wrong?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question