安装
1  | //vue-resource  | 
全局配置
vue-resource
 配置了全局默认设置后,在全局和组件的调用都不用带头部
   例如:Vue.http.get(url).then()
   this.$http.get(url).then()
   注意:配置了root后,url需是相对路径 1
2
3
4Vue.http.options.root = ' http://sfabric.sm/api/';
Vue.http.headers.common['Accept'] = 'application/json';
Vue.http.headers.common['X-Requested-With'] = 'XMLHttpRequest';
Vue.http.headers.common['Authorization'] = 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOi'
axios
 配置了全局配置后,在全局和组件的调用都不用带头部
   例如:Axios.get(url).then().catch()
   this.$http.get(url).then().catch()
   注意:配置了baseURL后,url需是相对路径 
1  | Axios.defaults.baseURL = 'http://sfabric.sm/api/';  | 
快捷方法和选项配置
1  | // vue-resource  | 
选项和配置解析
vue-resource options 选项说明
1  | url string 请求的目标URL  | 
axios config 配置说明
1  | {  | 
基本的http调用方式
全局调用
1  | // vue-resource  | 
组件实例调用
1  | // vue-resource  | 
respose对象
vue-resource response对象数据格式
1  | // vue-resource response对象数据格式  | 
axios response 对象数据格式
1  | 1. config:  | 
拦截器
vue-resource
1  | //请求的处理  | 
axios
1  | //请求拦截处理  | 
请求中断
vue-resource
1  | {  | 
axios
1  | 你可以通过cancel token来取消一个请求  |