vuejs之使用axios发送http请求

前端之家收集整理的这篇文章主要介绍了vuejs之使用axios发送http请求前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

看一个例子:

<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里再增加一个参数字典。

猜你在找的Vue相关文章