«

axios基本用法

yang 发布于 阅读:394 JS高阶阶段


什么是axios?
Axios 是一个基于 promise 的网络请求库,可以用于浏览器和 node.js

axios的用法

 <body>
        <script src="./axios.min.js"></script>
        <script>
            /*
            //发get请求,传参数
            axios.get('./data.txt', {
                params: {
                    id: 11,
                }
            }).then(res => {
                console.log(res)
            });
            */

            /*
            //发post请求,传参数
            axios.post('./data.txt', {
                username: '张三',
                age: 18,
            }).then(res => {
                console.log(res)
            });
            */

            //配置参数发请求-get请求
            axios({
                method: 'get',
                url: './data2.txt',
                params: {
                    id: 12,
                }
            }).then(res => {
                console.log(res);
            })

            //配置参数发请求-post请求
            /*
            axios({
                method: 'post',
                url: './data3.txt',
                data: {
                    id: 12,
                }
            }).then(res => {
                console.log(res);
            })
            */
        </script>
    </body>

axios基本用法

版权所有:微4e
文章标题:axios基本用法
除非注明,文章均为 微4e 原创,请勿用于任何商业用途,禁止转载

推荐阅读:


扫描二维码,在手机上阅读
请先 登录 再评论