Answer the question
In order to leave comments, you need to log in
How to delete an item via a confirm button?
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"
Answer the question
In order to leave comments, you need to log in
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
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)
}
},
actions: {
deleteContact({commit}, id) {
commit('deleteContact', id)
},
}
mutations: {
deleteСontact(state, id) {
const idx = contacts.findIndex(t => t.id === id);
localStorage.removeItem(state.contacts[idx])
},
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question