能夠諸如此類的封裝一下vue
/* * 公用提示窗 * @export * @param {string}[desc="確認操做"]彈框提示文字 * @param {string}[title="提示"]彈框標題 * @param{string}[confirmButtonName ='確認']確認按鈕文字 * @param {string}[cancelButtonName="取消"] 取消按鈕文字 * @param{boolean}[distinguishCancelAndClose = false]關係和取消是否執行同一方法 *@return * */ export function confirm (desc = '確認操做', title = '提示', confirmButtonName = '確認', cancelButtonName = '取消', distinguishCancelAndClose = false) { return this.$confirm(desc, title, { confirmButtonName: confirmButtonName, cancelButtonName: cancelButtonName, distinguishCancelAndClose: distinguishCancelAndClose, closeOnClickModel: false, type: 'warning', center: true }) }
xxx//vue submitSome(){ try(){ async utils.confirm.call(this,"確認要刪除嗎") const formData = { 'id':this.id } let res = await this.$post('/sss',formData) if(res.code===1){ //do something } }catch(e){ console.log(e) // 若是須要關閉和取消有所區別 if(e==='close'){ //do something }else if(e==='cancel'){ //do something } } }
this.$confirm肯定框內容換行顯示數組
// 把寫的提示信心須要換行的地方分紅數組 confirmText const confirmText = ['是否將此項移除?', '注意:移除後不可恢復。'] const newDatas = [] const h = this.$createElement for (const i in confirmText) { newDatas.push(h('p', null, confirmText[i])) } this.$confirm( '提示', { title: '提示', message: h('div', null, newDatas), showCancelButton: true, confirmButtonText: '肯定', cancelButtonText: '取消', type: 'warning' } ).then(() => { })