index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. mineSettingInfo:'528'
  31. },
  32. //tab点击
  33. switcher: function({currentTarget}) {
  34. this.updateData(currentTarget.dataset.index);
  35. },
  36. // 根据index 更新template
  37. updateData:function(index){
  38. let myIndex = index;
  39. let templates = this.data.tab[myIndex].templates;
  40. this.setData({
  41. myIndex,
  42. templates
  43. });
  44. if (myIndex == 0) {
  45. hotInit(this);
  46. }
  47. if (myIndex == 1) {
  48. followInit(this);
  49. }
  50. if (myIndex == 2) {
  51. myInit(this);
  52. }
  53. },
  54. onLoad: function (options) {
  55. if(options.index) {
  56. this.updateData(options.index)
  57. }
  58. hotInit(this)
  59. this.init();
  60. },
  61. //初始化数据
  62. init: function () {
  63. // httputil.getOpenidSessionKey((res) => {
  64. // console.log('微信的用户信息', res);
  65. // this.setData({
  66. // jurisdictionFlag: true
  67. // })
  68. // lookInit(this);
  69. // },(error) => {
  70. // console.log(error);
  71. // this.setData({
  72. // jurisdictionFlag: false
  73. // })
  74. // });
  75. }
  76. })