码迷,mamicode.com
首页 > Web开发 > 详细

vue-resource 中 get / post / jsonp 三种请求方式的异同

时间:2019-03-02 00:58:34      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:pos   call   需要   console   user   pap   hone   ams   lis   

let url = ‘http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=2‘;
let params ={
    params: {
        username: ‘zhangSan‘,
        pwd: ‘123456‘
    }

}

 

// get 请求
this.$http.get(url, params).then((res) => {
    console.log(res);
},(err) => {
    console.log(err);
})


//post 请求
this.$http.post(url, params,
    // 需要配置一下
    {emulateJSON: true}).then( (res) => {
    console.log(res)
 }, (err) => {
    console.log(err)
 })


// JSON 请求
let JSONparams ={
    params: {
        username: ‘zhangSan‘,
        pwd: ‘123456‘
    },
    jsonp: ‘callback‘ // 设置回调函数的参数的一个名字,默认是话是callback,
}
 this.$http.jsonp(url, JSONparams).then( (res) => {
    console.log(res);
}, (err) => {
    console.log(err);
})

vue-resource 中 get / post / jsonp 三种请求方式的异同

标签:pos   call   需要   console   user   pap   hone   ams   lis   

原文地址:https://www.cnblogs.com/showcase/p/10459322.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!