1.安装npm install axios --save

2.在main.js 里

import axios from 'axios'
Vue.prototype.$http = axios
 
3.在页面里使用
   post提交
this.$http.post('路径', {参数})
.then(
    success =>{

    },
    error =>{
    
    }         
)

 get提交

 

this.$http.get('路径, {
          params:{
            参数
          }
        })
        .then(
          success => {
            //   console.log(success.data,333)
          },
          error => {
            console.log(error)
          }
        )

  同时请求两个接口

       this.axios.all([
         this.axios.get('路径’),
         this.axios.get('路径')
       ]).then(
         this.axios.spread(function (userResp, reposResp) {
           // 上面两个请求都完成后,才执行这个回调方法
           console.log('User', userResp.data);
           console.log('Repositories', reposResp.data);
       })
      )

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
  • 2022-12-23
  • 2021-08-03
  • 2021-06-17
  • 2021-09-07
猜你喜欢
  • 2022-12-23
  • 2021-10-19
  • 2022-01-09
  • 2021-04-13
  • 2022-01-31
  • 2021-10-13
相关资源
相似解决方案