js 文件中 代碼
/**
* 生命周期函數--監聽頁面加載
*/
onLoad: function (options) {
var thit = this
wx.request({ //請求地址
url: 'http://127.0.0.1:8000/ss/w/',
method: 'get',
// data:{},//沒有數據可以不寫
header: { //請求頭
'content-type': 'application/json'
// "Content-Type": "application/x-www-form-urlencoded"
},
//如果在sucess直接寫this就變成了wx.request()的this了
success: function (res) {
// res.data相當於ajax里面的data,為后台返回的數據
//打印后台返回的數據
console.log(res.data.message)
//直接把后台返回的數據 賦值給names 就可以直接調用names了
thit.setData({ names: res.data.message })
}
})
},