微信小程序调取api

//举例轮播图
//1.wxml页面
微信小程序调取api
//2.js页面
const app = getApp()
data: {
banner:[],
imgUrl: app.imgURL,
},
微信小程序调取api
const _this=this;
{
//轮播图
console.log(‘开始请求轮播图’,new Date());
wx.request({
url: app.baseURL + ‘/wx/product/all_banner’,//接口地址
method:“POST”,
success:function(res){
console.log(res);
console.log(‘开始请求轮播图’,new Date());
_this.setData({
banner:res.data.data,
})
},
fail(res){
console.log(res);
}
})
}
微信小程序调取api
//3.app.js页面
微信小程序调取api
//书写接口
baseURL:‘https://api.inno-we.cn’,
imgURL:‘https://images.inno-we.cn/’,

注意在本地设置勾选上不校验合法域名,否则会报错
微信小程序调取api