//index.js //获取应用实例 const app = getApp() import { lookInit } from '../../component/look/look'; import { myInit } from '../../component/mys/mys'; import { searchInit } from '../../component/search/search'; import httpRequestApi from '../../utils/APIRequest'; import httputil from '../../utils/httputil'; Page({ data: { tab:[ { name: '看', templates: 'look', img: '../../static/image/look1.png', selectimg: '../../static/image/look2.png' }, { name: '搜', templates: 'search', img: '../../static/image/sou1.png', selectimg: '../../static/image/sou2.png' }, { name: '我的', templates: 'mys', img: '../../static/image/my1.png', selectimg: '../../static/image/my2.png' } ], ind: 0, templates: 'look', jurisdictionFlag: true }, //tab点击 switcher: function({currentTarget}) { let ind = currentTarget.dataset.ind; let templates = this.data.tab[ind].templates; //console.log(this.data[ind]) this.setData({ ind, templates }) if (ind == 1) { searchInit(this); } if (ind == 2) { myInit(this); } }, jurisdiction: function () { setTimeout(()=>{ this.init(); },1000) }, onLoad: function (options) { if(options.ind) { let ind = options.ind; let templates = this.data.tab[ind].templates; this.setData({ templates, ind, }) if (ind == 1) { searchInit(this); } if (ind == 2) { myInit(this); } } this.init(); }, //初始化数据 init: function () { httputil.getOpenidSessionKey((res) => { console.log('微信的用户信息', res); this.setData({ jurisdictionFlag: true }) lookInit(this); },(error) => { console.log(error); this.setData({ jurisdictionFlag: false }) }); } })