bangdan.js 1.5 KB

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