axios是一个http的请求库
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
axios的写法:
1、
<script>var url ="http://192.168.4.18:3000/search?keywords=你";axios.get(url).then(res=>{console.log(res)})</script>
2、
<script>axios.get("http://192.168.4.18:3000/search",{params:{keywords:"你"}}).then(res=>{console.log(res);})</script>
3、
<script>var url ="/search"axios({url,baseURL:"http://192.168.4.18:3000",method:"get",params:{keywords:"你"}}).then(res=>{console.log(res);})</script>
axios的封装以及使用:
http.js:
var baseURL = "http://192.168.4.18:3000/"function http({url,method="get",params={}}){return axios({url,baseURL,method,params})}
.html:
<script>http({url:"/album?id=96964667"}).then(res=>{console.log(res);})http({url:"/album",params:{id:"96964667"}}).then(res=>{console.log(res);})</script>
