在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 返回 Promise 且被 reject 是什么意思

返回 Promise 且被 reject 是什么意思

我在切換選項(xiàng)卡的時(shí)候會(huì)根據(jù)用戶的選擇來(lái)決定是否切換選項(xiàng)卡,選項(xiàng)卡用的是elemenui的tabs組件,我看文檔中有一個(gè)before-leave的方法如圖:

clipboard.png

我的代碼:

this.$confirm('您還未保存簡(jiǎn)介,確定需要離開嗎?', '提示', {
            confirmButtonText: '確定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            return true;
        }).catch(() => {
            return false
        });

當(dāng)我選擇取消的時(shí)候會(huì)returnfalse,但是這樣并沒有阻止切換,于是我隱隱感覺要用文檔中的這句話來(lái)阻止“返回 Promise 且被 reject,則阻止切換。”,
但是實(shí)在不知道怎么寫,求指教

回答
編輯回答
你的瞳

你應(yīng)該返回一個(gè) promise

return new Promise(resolve, reject) {

this.$confirm('您還未保存簡(jiǎn)介,確定需要離開嗎?', '提示', {
            confirmButtonText: '確定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            resolve()
        }).catch(() => {
            reject()
        });
}

試試吧

2017年6月14日 15:48
編輯回答
久礙你

直接把$confirm return回去試下,因?yàn)?code>$confirm本來(lái)就是返回一個(gè)Promise

return this.$confirm('您還未保存簡(jiǎn)介,確定需要離開嗎?', '提示', {
            confirmButtonText: '確定',
            cancelButtonText: '取消',
            type: 'warning'
        })
2018年5月3日 06:19
編輯回答
挽歌

試試這個(gè):

return new Promise((res,rej)=>{
    this.$confirm('您還未保存簡(jiǎn)介,確定需要離開嗎?', '提示', {
            confirmButtonText: '確定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            res()
        }).catch(() => {
            rej()
        });
}
        )
2018年4月12日 23:16