// pages/notice/notice.js Page({ /** * 页面的初始数据 */ data: { currentTab: 0, tabList: [{ "name": "工作通知" }, { "name": "预警警示" }, { "name": "系统通知" } ], pageList: [ { url: "/res/icons/notice_3.png" }, { url: "/res/icons/notice_1.png" }, { url: "/res/icons/notice_2.png" }, ] }, //计算swiper高度方法(在切换的时候调用) tabsHeight(element) { let that = this; let query = wx.createSelectorQuery(); //必须要先创建一个查询 query.select(element).boundingClientRect(function (rect) { that.setData({ pageheight: rect.height + 'px' }); }).exec(); }, swichNav: function (e) { var that = this; if (this.data.currentTab === e.target.dataset.current) { return false; } else { that.setData({ currentTab: e.target.dataset.current, navScrollLeft: e.target.dataset.current >= 4 ? ((e.target.dataset.current) * 60) : 0 //判断当前选中的个数是否是第5个 }) that.tabsHeight('.page'+e.target.dataset.current); //查询哪一个元素 } }, bindChange: function (e) { var that = this; that.setData({ currentTab: e.detail.current, navScrollLeft: e.detail.current >= 4 ? ((e.detail.current) * 60) : 0 //判断当前选中的个数是否是第5个 }); // that.tabsHeight('.page'+e.target.dataset.current); //查询哪一个元素 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.tabsHeight('.page0'); }, })