前端-vue基础79-promise中的常见api

 

<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
 
<body>
    <script>
        //console.dir(promise);
 
        function foo() {
            return new Promise(function(resolve, reject) {
                setTimeout(function() {
                    resolve(123);
                }, 100)
            })
        }
        foo()
            .then(function(data) {
                console.log(data);
            })
            .catch(function(data) {
                console.log(data);
            })
            .finally(function(data) {
                console.log('finished');
            })
    </script>
</body>
 
</html>

 

posted @ 2022-07-23 22:30  前端导师歌谣  阅读(21)  评论(0)    收藏  举报