🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
加载列表页数据 关键代码 app.js ~~~ App({ onLaunch: function() { } globalData: { doubanBase:"https://douban.uieee.com/v2" } }) ~~~ movie.js ~~~ // pages/movie.js var app = getApp(); Page({ data:{ inTheaters:{}, comingSoon:{}, top250:{} }, onLoad(){ var douban = app.globalData.doubanBase; var count = "?start=0&count=3" var inTheaterUrl = douban+"/movie/in_theaters"+count; var comingSoonUrl = douban+"/movie/coming_soon"+count; var top250Url = douban+"/movie/top250"+count; this.getMovieListData(inTheaterUrl,"inTheaters"); this.getMovieListData(comingSoonUrl,"comingSoon"); this.getMovieListData(top250Url,"top250"); }, getMovieListData(url,setKey){ var self = this; wx.request({ url, header: { 'Content-Type': 'json' }, success: function(res) { self.processData(res.data,setKey); }, fail: function(error) { console.log(error) } }) }, processData(moviesDouban,setKey){ var movies = []; for(var index in moviesDouban.subjects){ var top = moviesDouban.title; console.log(top) var subject = moviesDouban.subjects[index]; var title = subject.title; if(title.length>=6){ title =title.substring(0,6)+"..."; } var temp = { title, average:subject.rating.average, coverageUrl:subject.images.large, movieId:subject.id } movies.push(temp) } var readyData = {}; readyData[setKey] = { movies:movies, top } this.setData(readyData); console.log(this.data.inTheaters) } }) ~~~ [代码地址](https://gitee.com/chengbenchao/small_program/tree/master/mooc%E9%A1%B5%E9%9D%A2/15%E5%8A%A0%E8%BD%BD%E5%88%97%E8%A1%A8%E9%A1%B5%E6%95%B0%E6%8D%AE)