Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
95
rated 0 times [  100] [ 5]  / answers: 1 / hits: 68598  / 5 Years ago, sat, january 12, 2019, 12:00:00

i want to show a dialog box before deleting a files, how i can do it with vue?



here what i try



my button to delete a file



<a href=javascript:; v-on:click=DeleteUser(artist.id, index) onClick=return confirm('are you sure?');>Delete</a>


and here my delete method



DeleteUser(id, index) {
axios.delete('/api/artist/'+id)
.then(resp => {
this.artists.data.splice(index, 1);
})
.catch(error => {
console.log(error);
})
},


the dialog is showing but whatever i choose it keep delete the file.


More From » vue.js

 Answers
24

Try this



<a href=javascript:; v-on:click=DeleteUser(artist.id, index)>Delete</a>

DeleteUser(id, index) {

if(confirm(Do you really want to delete?)){

axios.delete('/api/artist/'+id)
.then(resp => {
this.artists.data.splice(index, 1);
})
.catch(error => {
console.log(error);
})
}
},

[#52782] Tuesday, January 8, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
collinisaaka

Total Points: 194
Total Questions: 105
Total Answers: 104

Location: Tonga
Member since Tue, Nov 30, 2021
3 Years ago
;