网上看了写文章,实际操作起来常出问题。尤其是微信小程序中大小写一定要区分开。
js代码如下
Page({
data: {
list: []
},
onLoad:
function () { //这个onLoad注意大小写区分,刚开始用小写总报错
var that =
this;
wx.request({
url:
'https://api.douban.com/v2/movie/top250',//这个地址好像只能https的
method:
"GET",
header: {
'Content-Type':
'json'
},
success:
function (res) {
console.log(res.data.subjects);
var date = res.data.subjects;
that.setData({
list: date
})
},
fail:
function () {
console.log(
"接口调用失败");
}
})
}
})
wxml代码比较简单如下:
<
block
wx:for=
"{{list}}">
<
view
class=
"title-name">{{item.title}}
</
view
>
</
block
>