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 '../../utils/hls';
  8. // import httpRequestApi from '../../utils/APIRequest';
  9. // import httputil from '../../utils/httputil';
  10. Page({
  11. data: {
  12. tab:[
  13. {
  14. name: '热门',
  15. templates: 'hot',
  16. },
  17. {
  18. name: '关注',
  19. templates: 'follow',
  20. },
  21. {
  22. name: '我的',
  23. templates: 'my',
  24. }
  25. ],
  26. myIndex: 0,
  27. templates: 'hot',
  28. title:'index中的title',
  29. jurisdictionFlag: true,
  30. hotInput:'12345'
  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. })