微信小程序调用API,首先你带有一个api,推荐聚合数据,百度一下,认证注册一下,会获得一个API,还有appkey。
话不多说,在默认的index.js里写
onLoad: function (options) {
wx.request({
url: 'http://v.juhe.cn/toutiao/index',//API比如我调用了聚合头条api,这个是免费的
data:{
key: '你自己获得到的appkey'
},
header: {
'content-type': 'application/json' ,// 默认值
},
success: (res) => {
console.log(res)
},
fail: (err) => {
console.log(err)
}
})
/*wx.showLoading({
title: '加载中',
})
//this.text();
*/
},














