vue axios 应用

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);
       })
      )

  

原文地址:https://www.cnblogs.com/zhoubingyan/p/8509421.html