The question about promise

a () {
    return new Promise((res, rej) => {
        // :
        getData().then(res => {
            this.data = res.data.reslut
            console.log(this.data)
        })
    });
}

the a method is defined in vue , and the a method is called in the click event of a button. The desired effect is that after the a method is executed, the alert is executed as follows:

click () {
    this.a().then(()=> {
        alert(11)
    })
}

in this way, the a method is in effect, but the following alert (11) is not triggered. Is something wrong? Or the writing is fundamentally wrong, please give me some advice.

Mar.01,2021

a () {
    return new Promise((resolve,reject) => {
        getData().then(res => {
            this.data = res.data.reslut
            console.log(this.data)
            resolve(this.data);
        })
    });
}

you didn't change the promise state with resolve, so you didn't go to the then callback. The code has been given above, so I won't repeat it again.


resolve changes the current state of the promise object to success, and reject turns the current state of the promise object into a failure, and the execution of then will not continue until the state changes.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be07cb-314f5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be07cb-314f5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?