微信小程式系列4(網路請求)
阿新 • • 發佈:2019-01-10
wx.request(OBJECT)發起https請求
第一點要注意的是微信小程式只支援https,而且需要在微信公眾平臺後臺設定配置伺服器域名
考慮到前期開發階段不一定弄了https支援或一些校驗,所以可以在微信開發工具專案一欄暫時勾上關閉域名驗證這一選項,https免費配置參考教程[去看看]
引數和回撥說明
這裡以模擬登入為例
loginSelf: function() {
//模擬登入進度條
wx.showToast({
title: '登入中...',
icon: 'loading',
})
//發起請求
wx.request({
url: 'http://xxx/user/login',
data: {
name: 'honaf' ,
password: '123456'
},
method:'post',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function(res) {
console.log(res)
//登入成功做相應處理
if(res.data.status == 1){
wx.showToast({
title: "登入成功",
icon: 'success',
duration: 1000
})
}
}
})
},
res列印結果如下