美文网首页
pomsie.all 练习(转载)两个实例代码

pomsie.all 练习(转载)两个实例代码

作者: 糖醋里脊120625 | 来源:发表于2019-06-28 11:51 被阅读0次
    <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.3, minimum-scale=1.0">
            <title>入库接收</title>
            <link rel="stylesheet" href="https://unpkg.com/mint-ui/lib/style.css">
        </head>
        <body>
            <div id="app">
    
            </div>
            <script src="https://unpkg.com/vue/dist/vue.min.js"></script>
            <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
            <script src="https://unpkg.com/mint-ui/lib/index.js"></script>
            <script src="https://unpkg.com/vue-resource@1.5.1/dist/vue-resource.js"></script>
            <script>
                {
                    const p1 = axios.get('https://easy-mock.com/mock/5b0525349ae34e7a89352191/example/promise1')
                        .then(
                                ({
                                    data
                                }) => {
                                    console.log('p1成功啦');
                                    return data.data
                                }
                            )
                    const p2 = axios.get('https://easy-mock.com/mock/5b0525349ae34e7a89352191/example/promise2')
                        .then(({
                            data
                        }) => {
                            console.log('p2成功啦');
                            return data.data
                        })
                    const p3 = axios.get('https://easy-mock.com/mock/5b0525349ae34e7a89352191/example/mock')
                        .then(({
                            data
                        }) => {
                            console.log('p3成功啦');
                            return data.data
                        })
    
    
                    const p = Promise.all([p3, p1, p2])
                        .then(arr => {
                            console.log(arr);
                            console.log('Promise.all成功啦');
                        })
                        .catch(err => {
                            console.log(err, 'Promise.all错啦');
                        })
                }
            </script>
        </body>
    
    </html>
    
    

    2

    <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.3, minimum-scale=1.0">
            <title>入库接收</title>
            <link rel="stylesheet" href="https://unpkg.com/mint-ui/lib/style.css">
        </head>
        <body>
            <div id="app">
    
            </div>
            <script src="https://unpkg.com/vue/dist/vue.min.js"></script>
            <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
            <script src="https://unpkg.com/mint-ui/lib/index.js"></script>
            <script src="https://unpkg.com/vue-resource@1.5.1/dist/vue-resource.js"></script>
            <script>
                {
                    const httpUrl = 'http://39.105.17.99:8080/'
                    function promiseFun(url, params) {
                        return new Promise((resolve, reject) => {
                            this.$http.post(this.globalHttpUrl + url, params).then(
                                (res) => {
                                    resolve(res.json())
                                },
                                (err) => {
                                    reject(err.json())
                                }
                            )
                        })
                    }
                    var p1 = Promise.resolve(1)
                    var p2 = Promise.resolve(2)
                    var p3 = Promise.resolve(3)
                    Promise.all([promiseFun, p1, p2, p3]).then((res) => {
                        console.log(res, 'promise all 方法')
                    })
                }
            </script>
    
    
    
    
    
    
        </body>
    
    </html>
    
    

    相关文章

      网友评论

          本文标题:pomsie.all 练习(转载)两个实例代码

          本文链接:https://www.haomeiwen.com/subject/xmjscctx.html