resource插件讲解:
- get请求一般都是客户端向服务端请求东西
params
:{
userId
:
"101"
}
, 数据是放在这个里面的
.then(res=>{
this
.msg=res.
data
;
}
,
error
=>{
this
.
msg
=
error
;
})
; 这里是放成功和失败所返回的数据的
- post请求和get请求都是差不多的,不一样的是没有params其余的都一样
- jsonp请求就是解决跨越问题,通过增加src 来直接访问这个网站
axios插件讲解:
- 也是和resource一样有三个请求,get post 和http 但是没有jsonp请求,还有一个全局拦截器,目的是吧所有的请求拦截在一起 然后一起发送,这个vue-resource 多用下就好了的其实也不难
- mounted:function(){
axios.
interceptors
.
request
.
use
(
function
(config){
console
.
log
(
"request init."
)
;
return
config
;
})
axios.
interceptors
.
response
.
use
(
function
(response){
console
.
log
(
"response init"
)
;
return
response
;
}) 全局拦截器代码
}