Vue自学笔记(二)跟的b站黑马快速入门vue

该博客演示了如何在网页中使用axios库进行GET和POST请求。通过点击按钮,实现了从'https://autumnfish.cn/api/joke/list'获取笑话列表的GET请求,以及向'https://autumnfish.cn/api/user/reg'发送用户名为'盐焗虾'的POST注册请求。响应内容会在浏览器控制台显示。
摘要由CSDN通过智能技术生成

在这里插入图片描述
axios请求的github源码地址

<!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>
    
    <!-- axios.get(地址?查询字符串).then(function(response){},function(err){} )
    axios.post(地址,{key:value,key2:value2}).then(function(response){},function(err){}) -->
    <!--key=value&key2=value2-->
    <input type="button" value="get请求" class="get">
    <input type="button" value="post请求" class="post">
<!--尝试用axios的get请求获取笑话,post请求登录-->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        document.querySelector(".get").onclick = function(){
            axios.get("https://autumnfish.cn/api/joke/list?num=3")
            .then(function(response){
                console.log(response);
            },function(err){
                coonsole.log(err);
            }
            
            ) 
        }
        document.querySelector(".post").onclick=function(){
            axios.post("https://autumnfish.cn/api/user/reg",
           {username:"盐焗虾"} )
           .then(function(response){
               console.log(response);
           },function(err){
               console.log(err);
           })
        }
       
    </script>
</body>
</html>

完成后在网页控制台可以看见相关内容

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值