Axios
发送GET请求
axios({ // 请求方式 method: "GET", // 请求地址 url: "http://www.liulongbin.top:3006/api/getbooks", // URL中的查询参数 params: { id: 2, }, }).then(function(result) { console.log(result); }) });
发送post请求
<!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>Document</title> </head> <body> <button id="btnPost">发送POST请求</button> <!-- 引入axios --> <script src="/lib/axios.js"></script> <script> document.querySelector('#btnPost').addEventListener('click', function() { axios({ method: 'POST', url: 'http://www.liulongbin.top:3006/api/post', // 请求体参数 data: { name: 'zs', age: 12, } }).then(function(result) { console.log(result); }) }) </script> </body> </html>
标签:function,www,axios,请求,api,Vue,result From: https://www.cnblogs.com/ZhuAo/p/16834413.html