1. 程式人生 > 程式設計 >element中的$confirm的使用

element中的$confirm的使用

可以諸如此類的封裝一下

/*
 * 公用提示窗
 * @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',newDatas),showCancelButton: true,confirmButtonText: '確定',cancelButtonText: '取消',type: 'warning' 
   } ).then(() => { })

到此這篇關於element中的$confirm的使用的文章就介紹到這了,更多相關element $confirm 內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!