zoukankan      html  css  js  c++  java
  • Vue.js的ajax

    1. vue-resource是vue.js的插件提供了使用XMLHttpRequest或JSOUP进行web请求和处理响应的服务。但是当vue更新到2.0后,宣布不再更新,而是推荐了axios.因此,对于其只需要了解就行

    2. Axios是一个基于promise的HTTP库

    3. 引入axios

      <script type="text/javascript" src="js/axios.js"></script>
    4. get请求

      axios.get('/user?ID=12345')
        .then(function(response){
        console.log(response);
        })
        .catch(function(err){
        console.log(err);
        })
      //也可以通过下面这种方式进行请求
      axios.get('user',{
      params:{
      ID:12345
      }
      })
      .then(function(response){
      console.log(response);
      })
      .catch(function(err){
      console.log(err);
      });

    5.post请求

    axios.post('user',{
    firstName:'Fred',
    lastName:'Flintstone'
    })
    .then(function(res){
    console.log(res);
    })
    .catch(function(err){
    console.log(err);
    });

    6.为方便起见。为所有支持的请求方法提供了别名

    axios.request(config)
    axios.get(url[,config])
    axios.delete(url[,config])
    axios.head(url[,config])
    axios.post(url[,data[,config]])
    axios.put(url[,data[,config]])
    axios.patch(url[,data[,config]])

     

  • 相关阅读:
    sprint2(第九天)
    sprint2 (第八天)
    sprint2(第七天)
    sprint2(第六天)
    sprint2(第四天)
    sprint2(第三天)
    sprint2(第二天)
    sprint 2(第一天)
    0621 第三次冲刺及课程设计
    0617 操作系统实验4 主存空间的分配和回收
  • 原文地址:https://www.cnblogs.com/juddy/p/13290620.html
Copyright © 2011-2022 走看看