天天看點

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
        }
      })