axios配置信息

106 阅读1分钟
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js"></script>
</head>
<body>
    <script>
        // http://123.207.32.32:8000/home/multidata
        // http://123.207.32.32:8000/home/data?type=pop&page=

        // 配置全局的axios 信息
        axios.defaults.baseURL = "http://123.207.32.32:8000";
        // 设置延迟时间,如果超过5秒没有得到响应,就超时了。
        axios.defaults.timeout = 5000
        axios.all([axios({
            url:'/home/multidata'
            }),axios({
            url:'/home/data',
            params:{
                type:'pop',
                page:2
            }
            })])
            .then(axios.spread((value1,value2) => {
                console.log(value1);
                console.log(value2);
            }))
    </script>
</body>
</html>