let {data:res} =  await axios.get('http://127.0.0.1:4000',{
                    params:{
                        name:'三体'
                    }
                 })
                console.log(res);

 1.是get请求方式案例

methods: {
            //    1.请求方法 get post
            
           /* 第一种方法 */ 
            // async login() {
            //   let {data:res} = await  axios({
            //         method: 'post',
            //         url: 'http://www.chenfuguo.cn:3333/users/login  ',
            //         data: {
            //             uname: 'admin',
            //             upwd: '123456'
            //         }
            //     })
            //     console.log(res);
            // }

            /* 第二种方法 */
            async login(){
               let {data:res} = await axios.post('http://www.chenfuguo.cn:3333/users/login',{
                        uname: 'admin',
                        upwd: '123456'
                })
                console.log(res);
            }
        }

2.是post请求案例 

 async all(){
                 let res = await axios.all([this.login(), this.getVal()]);
                console.log(res);

            }

3.是axios进行多个

4.进行axios创建实例

<!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>get请求数据</title>

</head>

<body>
    <div id="app">
        <button @click="login">axiosPost请求</button>
        <button @click="getVal()">get请求</button>
        <button @click="all()">axios请求</button>
    </div>
</body>

</html>
<script src="./js/vue.js"></script>
<script src="./js/axios.min.js"></script>
<script>

    const http = axios.create({
        baseURL:'http://www.chenfuguo.cn:3333'
    })
    let vm = new Vue({
        el: '#app',//el表示挂载 关联页面元素

        data: {

        },
        methods: {
            //    1.请求方法 get post
            /* 第二种方法 */
          async  login(){
            let{data:res} = await http.post('http://www.chenfuguo.cn:3333/users/login',{
                        uname: 'admin',
                        upwd: '123456'
                })
                console.log(res);
               
            },
          async  getVal(){
            let{data:res}  = await  http.get('http://127.0.0.1:4000',{
                    params:{
                        name:'三体'
                    }
                })
                console.log(res);
            },
           async all(){
                 let res = await axios.all([this.login(), this.getVal()]);
                console.log(res);

            }
        }
    })
</script>

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐