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]])

     

  • 相关阅读:
    git安装和使用
    GitHub入门
    jmeter入门
    this关键字
    ES6函数
    代码雨
    this指向练习题
    a标签阻止默认跳转行为事件
    模板引擎的应用
    面向对象
  • 原文地址:https://www.cnblogs.com/juddy/p/13290620.html
Copyright © 2011-2022 走看看