appjs中的代码
//回调函数封装wx.request
//geturl:请求地址
//callback:请求成功的回调函数
//因为异步的请求机制,我们不能在其success()中直接返回需要的数据
getData1(geturl,callback){
wx.request({
url: geturl,//注意不加引号
success:(res)=>{
callback(res.data)//回调函数 非异步
},
fail(err){
callback(err) //如果错误将错误的信息报出
}
})
},
index中
indexjs中的代码
//从服务器获取数据,条件isgood>0
//let that = this;
//代替request
// let geturl=`${url}/db/list1.php?where=isgood>0`,
let geturl='http://192.168.43.247/db/list1.php?where=isgood>0';
app.getData1(geturl,(res)=>{
console.log(res)
})
},//onload结束