做網(wǎng)站有哪些平臺宣傳推廣方案
多選刪除一般有兩種情況:
1,刪除接口支持傳多個id,這是最理想的方法,建議大家積極與后端進(jìn)行溝通解決。之后只需要判斷接口回調(diào)刷新頁面即可!
2,刪除接口不支持傳多個id,這就是接下來我們要處理的情況,利用promise.all來解決,親測有效,接下來盡量用最通俗的語言和代碼為大家解釋!
if (this.selectRows.length > 0) { //以下為多選方法*******const ids = this.selectRows.map((item) => item.id);//取出所有需要刪除的id*****this.$confirm("你確定要刪除選中項嗎", "提示", {confirmButtonText: "確定",cancelButtonText: "取消",type: "warning",center: true,}).then(() => {var promiseList = new Set();//生成一個唯一的集合******ids.forEach(async (item) => {//循環(huán)操作添加promise*****let promise = function () {return new Promise(async (resolve) => {let res = await crmCustomerDel(item);//crmCustomerDel為刪除api ******if (res.code == 200) {resolve();}});};promiseList.add(promise());});Promise.all(promiseList).then(async (result) => {this.getInfo();//為頁面初始化方法******console.log(result);}).catch((error) => {console.log(error);});this.$message({type: "success",message: "刪除成功!",});}).catch(() => {this.$message({type: "error",message: "刪除失敗",});});
之后大家復(fù)制這段代碼,更改為自己的刪除api即可,最后希望幫到你,回來幫我點個贊!!!