vue相关ajax库的使用

 相关库:

      vue-resource: vue插件, 多用于vue1.x

        axios: 第三方库, 多用于vue2.x

    vue-resource使用

        // 引入模块

        import VueResource from 'vue-resource'

        // 使用插件

        Vue.use(VueResource)

        

        // 通过vue/组件对象发送ajax请求

        this.$http.get('/someUrl').then((response) => {

          // success callback

          console.log(response.data) //返回结果数据

        }, (response) => {

          // error callback

          console.log(response.statusText) //错误信息

        })

    axios使用

        // 引入模块

        import axios from 'axios'

        

        // 发送ajax请求

        axios.get(url)

          .then(response => {

            console.log(response.data) // 得到返回结果数据

          })

          .catch(error => {

        console.log(error.message)

          })

原文地址:https://www.cnblogs.com/songhongye/p/10375562.html