1.首先是引入 

或者用npm来安装  cnpm i vue-resource --save(推荐)

3.提供的api

关于请求写法:

get(){
// get请求
this.$http.get( // get方法里面('地址',{params:{},headers{}); 由于是get方法所以参数都要放到params里面 然后整个参数被对象包括
'package.json',
{
params:{
userId:'101'
},
headers:{
token:'abcd'
}
}
).then(
res=>{
this.msg = res.data;
},
error=>{
this.msg = error;
}
);
},
post(){
// post请求
this.$http.post( //post方法里面 post('地址',{userId:''},{headers:{}}) post方法参数直接在一个对象里面写 然后请求头也是单独一个函数里面写
'package.json',
{
userId:'102'
},
{
headers:{
access_token:'abscd'
}
}
).then(
res=>{
this.msg = res.data
}
)
}
//jsonp 请求 实际是<script>ajax传输 能解决跨域
jsonp(){
 this.$http.jsonp('http://www.imooc.com/course/AjaxCourseMembers?ids=866').then(res=>{
  this.msg = res.data;
  });
}
//在mounted里面可以写全局拦截
// 全局拦截 全部的请求
Vue.http.interceptors.push(function(res,next){
  console.log('请求前');   next(respon=>{
      console.log('请求后');
return respon;
});
});
// methosd同级方法 http{} 能统一定义请求路径
http:{
root:'http://localhost:63342/vueactual/ops/156'
}
http 方式 类似jq ajax
ajax(){
this.$http({
url:'package.json',
params:{
userId:'123'
},
headers:{
token:'123',
tokens:'123'
},
timeout:50,
before:function(){
console.log('before init')
} }).then(res=>{
this.msg = res.data;
});
}
 
												

最新文章

  1. PHP_环境配置_python脚本_2017
  2. ASP.NET MVC中给所有的cshtml页面引用命名空间
  3. N[开源].NET CORE与MySql更配, MySqlSugar ORM框架 3.x
  4. js循环添加事件的问题
  5. android cocos2d-x for Android安装和学习笔记(请用adt-bundle21.1或以上导入)
  6. 转载 uboot 命令
  7. The future of programming languages
  8. Ajax ContentType 列表
  9. 如何避免JavaScript的内存泄露及内存管理技巧
  10. wince 位图的使用
  11. 学习hash_map从而了解如何写stl里面的hash函数和equal或者compare函数
  12. IOS-开发日志-UITextField属性
  13. 手势滑动结束 Activity(一)基本功能的实现
  14. es6 Module
  15. 分享我自己的一个最小化安装CentOS6的初始化脚本
  16. 在模态框(Modal)中使用UEditor全屏显示的一个坑
  17. php 会话控制(关于session的维护与生命周期)
  18. centos6.5系统bash损坏之救援模式修复
  19. PHP 如何自定义函数
  20. js实现点击div以外区域,隐藏div区域

热门文章

  1. gradle下载jar包
  2. 《Java程序设计》 第一周学习总结
  3. C++: typedef与template的配合使用;
  4. jmeter5.0 while controller使用总结
  5. Spring Cloud构建微服务架构(六)高可用服务注册中心
  6. perl trick
  7. Hadoop生态圈-Ranger数据安全管理框架
  8. MySQL数据类型1
  9. 细说log4j之概述
  10. 错误 1 “Entities.PlanPrjEntity.PlanPrjs”不可访问,因为它受保护级别限制