请求

作者: jasmine_6aa1 | 来源:发表于2020-04-01 17:15 被阅读0次
  • get请求
  • post请求
  • Jsonp请求
    这里是基于 vue 框架写的方法,主要是参考请求中的参数

get请求:两个参数

  • 一个是url地址
  • 一个是option -- 没有可省略
getFor(){
         this.$http.get('http:vue.studyit.io/api/getlunbo').then(function(result){
            console.log(result.body)//这里一般用body
            })
        },

post请求:三个参数

  • 一个是url地址
  • 一个是body数据
  • 一个是option -- 不可省略
    post请求,默认格式 application/x-www-form-urlencoded
postFor(){
 //通过post方法的第三个参数,{elementJSON:true}设置提交的内容类型 为普通表单数据格式
     this.$http.post('http:vue.studyit.io/api/getlunbo',{},{elementJSON:true}).then(function(result){
                console.log(result.body)
            })
        },

Jsonp请求:三个参数

  • 一个是url地址
  • 一个是body数据
  • 一个是option -- 可省略
JsonpFor(){
  this.$http.Jsonp('http:vue.studyit.io/api/getlunbo').then(function(result){
                console.log(result.body)
            })
        },

相关文章

网友评论

      本文标题:请求

      本文链接:https://www.haomeiwen.com/subject/oumauhtx.html