current position:Home>[Axios learning] basic use of Axios

[Axios learning] basic use of Axios

2022-04-29 19:28:33Raise the sun

1、 Use Default mode send out No arguments request

By default get request

<script src="https://unpkg.com/axios/dist/axios/main.js"></script>
<script>
   axios({
      url:'https://localhost:9999/student/student/getAllStudent'
   }).then(res=>{
      console.log(res)
   })
</script>

2、 Use The request method is get Of No arguments request

<script src="https://unpkg.com/axios/dist/axios/main.js"></script>
<script>
   axios({
      url:'https://localhost:9999/student/student/getAllStudent',
      method:'get'
   }).then(res=>{
      console.log(res)
   })
</script>

3、 Use get The way send out Ginseng request

<script src="https://unpkg.com/axios/dist/axios/main.js"></script>
<script>
   axios({
      url:'https://localhost:9999/student/student/findStudentById?id=1',
      method:'get'
   }).then(res=>{
      console.log(res)
   })
</script>

4、 send out get Other forms of request

<script src="https://unpkg.com/axios/dist/axios/main.js"></script>
<script>
   axios({
      url:'https://localhost:9999/student/student/findStudentById',
      params:{
         id:'1',
         name:' Zhang San '
      }
   }).then(res=>{
      console.log(res)
   })
</script>

5、 Use post The way send out No participation request

<script src="https://unpkg.com/axios/dist/axios/main.js"></script>
<script>
   axios({
      url:'https://localhost:9999/student/student/pGet'
      method:'post'
   }).then(res=>{
      console.log(res)
   })
</script>

 6、 Use post The way send out Participation request

<script src="https://unpkg.com/axios/dist/axios/main.js"></script>
<script>
   axios({
      url:'https://localhost:9999/student/student/findStudentByName',
      method:'post',
      params:{
        name:' Zhang San '
      }
   }).then(res=>{
      console.log(res)
   })
</script>

copyright notice
author[Raise the sun],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204291743389693.html

Random recommended