bangdan.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const app = getApp();
  2. // 定义一个全局变量保存从接口获取到的数据,以免重复请求接口
  3. var resut;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. currentTab:0,
  10. navTitle:[
  11. {title:'经典必听'},
  12. {title:'优质专辑'},
  13. {title:'有声小说'},
  14. {title:'儿童教育'},
  15. {title:'人文历史'},
  16. {title:'最潮外语'},
  17. {title:'商业财经'},
  18. {title:'热门新闻'}
  19. ]
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. var that = this;
  26. wx.request({
  27. url: 'http://mobile.ximalaya.com/mobile/discovery/v3/recommend/hotAndGuess?code=43_310000_3100&device=android&version=5.4.45',
  28. header: {'content-type':'application/json'},
  29. method: 'GET',
  30. dataType: 'json',
  31. responseType: 'text',
  32. success: (res)=>{
  33. resut = res;
  34. console.log(res);
  35. that.setData({
  36. list: res.data.hotRecommends.list[0].list
  37. })
  38. },
  39. fail: ()=>{},
  40. complete: ()=>{}
  41. });
  42. },
  43. handleClick(e) {
  44. let currentTab = e.currentTarget.dataset.index;
  45. // 实现每一个tabbar切换对应内容的原理,根据每一个tabbar的index对应数组中的数据
  46. this.setData({
  47. currentTab,
  48. list: resut.data.hotRecommends.list[currentTab].list
  49. })
  50. },
  51. pullDown:function(){
  52. }
  53. })