index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. import { hotInit } from '../../component/hot/hot';
  5. import { myInit } from '../../component/my/my';
  6. import { followInit } from '../../component/follow/follow';
  7. // import httpRequestApi from '../../utils/APIRequest';
  8. // import httputil from '../../utils/httputil';
  9. Page({
  10. data: {
  11. tab:[
  12. {
  13. name: '热门',
  14. templates: 'hot',
  15. },
  16. {
  17. name: '关注',
  18. templates: 'follow',
  19. },
  20. {
  21. name: '我的',
  22. templates: 'my',
  23. }
  24. ],
  25. myIndex: 0,
  26. templates: 'hot',
  27. title:'index中的title',
  28. jurisdictionFlag: true,
  29. hotInput:'12345'
  30. },
  31. //tab点击
  32. switcher: function({currentTarget}) {
  33. this.updateData(currentTarget.dataset.index);
  34. },
  35. // 根据index 更新template
  36. updateData:function(index){
  37. let myIndex = index;
  38. let templates = this.data.tab[myIndex].templates;
  39. this.setData({
  40. myIndex,
  41. templates
  42. });
  43. if (myIndex == 0) {
  44. hotInit(this);
  45. }
  46. if (myIndex == 1) {
  47. followInit(this);
  48. }
  49. if (myIndex == 2) {
  50. myInit(this);
  51. }
  52. },
  53. onLoad: function (options) {
  54. if(options.index) {
  55. this.updateData(options.index)
  56. }
  57. hotInit(this)
  58. this.init();
  59. },
  60. //初始化数据
  61. init: function () {
  62. // httputil.getOpenidSessionKey((res) => {
  63. // console.log('微信的用户信息', res);
  64. // this.setData({
  65. // jurisdictionFlag: true
  66. // })
  67. // lookInit(this);
  68. // },(error) => {
  69. // console.log(error);
  70. // this.setData({
  71. // jurisdictionFlag: false
  72. // })
  73. // });
  74. }
  75. })