前端培训之vue-resource 的使用

1.vue 项目中常用的 2 个 ajax 库
1.1.vue-resource
vue 插件, 非官方库,vue1.x 使用广泛
1.2.axios
通用的 ajax 请求库, 官方推荐,vue2.x 使用广泛
2.vue-resource 的使用
2.1. 在线文档
https://github.com/pagekit/vue-resource/blob/develop/docs/http.md
2.2. 下载
npminstallvue-resource–save
2.3. 编码
// 引入模块

importVueResourcefrom’vue-resource’

// 使用插件

Vue.use(VueResource)
// 通过 vue/组件对象发送 ajax 请求

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

         //successcallback

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

},(response)=>{

        //errorcallback

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

想要了解跟多关于前端培训课程内容欢迎关注尚硅谷前端培训,尚硅谷除了这些技术文章外还有免费的高质量前端培训课程视频供广大学员下载学习


上一篇:
下一篇: