vue学习(10)-vue-resource

下载:cnpm i vue-resource --save
在main.js导入包:import VueResource from 'vue-resource'
安装:Vue.use(VueResource)
 

使用:
this.$http.get('./url').then(result => { })
this.$http.post('./url',{body},{emulateJSON:true}).then(result => { console.log(result.body)})
this.$http.jsonp('./url').then(result => { })
result.body返回成功的数据
{emulateJSON:true}配置对象,因为post请求,要表单格式
post是要三个参数
不允许ajax发送跨域请求(协议,域名,端口号)=>解决:jsonp
 
配置全局请求:
Vue.http.option.root = ' '
Vue.http.option.emulate = true
下面的URL,用相对路径,前面不加/
posted @ 2019-08-15 17:11  MonicaJIN  阅读(370)  评论(0编辑  收藏  举报