天天看点

uniapp的请求request写法

let view=this;//因为下面不是箭头函数,普通函数指向window对象
      uni.request({
        url:"http://localhost/tp5/publica/index/web/view",
        method:"POST",
        data:{
          name:view.title
        },
        dataType:'json',//设置json返回值就会json.parse
        header:{
          "Content-Type":"application/x-www-form-urlencoded"
        },
        success(res) {
          console.log(res.data)
          view.text=res.data.text[0].imgNr
        }
      })