加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vuejs之使用axios发送http请求

发布时间:2020-12-16 23:03:07 所属栏目:百科 来源:网络整理
导读:看一个例子: html head script src ="https://unpkg.com/axios/dist/axios.min.js" / script / body input type ="button" value ="get请求" class ="get" ="post请求" ="post" document.querySelector(".get").onclick = function () { axios.get('https:/

看一个例子:

<html>

head>
  script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</bodyinput type="button" value="get请求" class="get"="post请求"="post">
    document.querySelector(".get").onclick = function () {
      axios.get('https://autumnfish.cn/api/joke/list?num=3')
        .then(function (response) {
          console.log(response);
        })
    }
    document.querySelector(".post").onclick = function () {
      axios.post('https://autumnfish.cn/api/user/reg',{ username: "西西嘛呦" })
        .then(function (response) {
          console.log(response);
        })
    }

  >

效果:

点击get请求:

点击post请求:

说明:

引入:<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

格式:axios.请求方式(请求网址).then(function(response){})。

如果是get请求,在地址后面用?带上参数,如果是post请求,在post里再增加一个参数字典。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读