vue-request发起网络数据请求
首先要引入vue-request.js,且顺序在vue.js后面,vue-request.js依赖与vue.js//get方式发起网络数据请求getInfo(){this.$http.get('URL').then(function(result){console.log(result.body)})}//post方式发起网络数据请求//post需要设置第三个参数postI...
·
首先要引入vue-request.js,且顺序在vue.js后面,vue-request.js依赖与vue.js
//get方式发起网络数据请求
getInfo(){
this.$http.get('URL').then(function(result){
console.log(result.body)
})
}
//post方式发起网络数据请求
//post需要设置第三个参数
postInfo(){
this.$http.post('URL',{提交给服务器的数据,不能省略,可以用空花括号},{emulateJSON:true}).then(function(result){
console.log(result.body)
})
}
//JSONP方式
jsonp(){
this.$http.jsonp('URL').then(result=>{
console.log(result.body)
//控制台输出的数据格式需要序列化,字符串序列化为json对象
})
}
更多推荐
已为社区贡献3条内容
所有评论(0)