[Vuejs]-Vue.js how to keep the todo when the no keep it button (cancel button) is clicked?

0๐Ÿ‘

โœ…

I believe the issue is with your Sweet Alert promise.

You are splicing the todos whether the confirm or cancel button was clicked.

Move your splicing into the if(result.value) condition and you should be ok.

deleteTodo(todo) {
    this.$swal({
        title: 'Are you sure?',
        text: 'You can\'t revert your action',
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#DD6B55',
        confirmButtonText: 'Yes, delete it!',
        cancelButtonText: 'No, Keep it!',
        showCloseButton: true,
    }).then((result) => {
        if (result.value) {
            const todoIndex = this.todos.indexOf(todo);
            this.todos.splice(todoIndex, 1)
            this.$swal('Deleted!', 'Your Todo has been deleted', 'success')
        }
        else{
            this.$swal('Canceled', 'Your Todo is still in place', 'info')
        }

    });
},
๐Ÿ‘คCUGreen

Leave a comment