[英]How to alert and deleted a task using Sweet alert and vue.js?
我收到Sweet Alert的確認警報消息,但是單擊確認消息后,無法刪除任務。
methods: {
confirmDelete: function(index) { //index is passed by the button
//var self = this;
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
closeOnConfirm: true
}, function(isConfirm) {
if (isConfirm) {
this.contacts.splice(index, 1);
swal(
'Deleted!',
'Your file has been deleted.',
'success'
);
return true;
} else {
return false;
}
}.bind(this));
}
}
可能的問題是this
語句嘗試執行以下操作:
var self = this;
function(isConfirm) {
if(isConfirm){
self.contacts.splice(index, 1);
swal(
'Deleted!',
'Your file has been deleted.',
'success'
);
return true;
}
else{
return false;
}
工作版本: https : //jsfiddle.net/jyfdh32g/
我更改了什么:vue版本到最后一個穩定版本-1.0.25確認按鈕動作樣式: https ://limonte.github.io/sweetalert2/示例。
為什么$index
不起作用?
參數順序更新:不建議使用arr中的(值,索引),obj $ index和$ key中的(值,鍵,索引)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.