What does it mean to return Promise and be reject

when I switch tabs, I will decide whether to switch tabs according to the user"s choice. The tabs use the tabs component of elemenui. I think there is a before-leave method in the document as shown in figure

.

clipboard.png

my code:

this.$confirm("?", "", {
            confirmButtonText: "",
            cancelButtonText: "",
            type: "warning"
        }).then(() => {
            return true;
        }).catch(() => {
            return false
        });

returnfalse, when I choose to cancel, but this does not prevent switching, so I vaguely feel that I want to use this sentence in the document to prevent "returning Promise and being blocked by reject,." ,
but I really don"t know how to write it. Ask for advice

Apr.02,2021

directly put $confirm return back to try, because $confirm originally returns a Promise

.
return this.$confirm('?', '', {
            confirmButtonText: '',
            cancelButtonText: '',
            type: 'warning'
        })

try this:

return new Promise((res,rej)=>{
    this.$confirm('?', '', {
            confirmButtonText: '',
            cancelButtonText: '',
            type: 'warning'
        }).then(() => {
            res()
        }).catch(() => {
            rej()
        });
}
        )

you should return a promise

return new Promise(resolve, reject) {

this.$confirm('?', '', {
            confirmButtonText: '',
            cancelButtonText: '',
            type: 'warning'
        }).then(() => {
            resolve()
        }).catch(() => {
            reject()
        });
}

try it

Menu