const { TAB_BAR_HEIGHT } = require("./constants"); Component({ //组件的初始数据, // 下面list中的 iconClass根据你自己下载的 iconfont里面的class名称对应修改 data: { selected: 0, selectedColor: "#6891fe", color: "#737375", tabBarHeight:TAB_BAR_HEIGHT, list: [{ "pagePath": "/pages/question/question", "text": "问答", "iconClass":"icon-wenda" }, { "pagePath": "/pages/scene/scene", "text": "场景", "iconClass":"icon-yingyongchengxu" }, { "pagePath": "/pages/my/my", "text": "我的", "iconClass":"icon-wode" } ] }, /** * 组件方法 */ methods: { /** 切换tab方法 */ switchTab(e) { const data = e.currentTarget.dataset const taburl = data.path let that = this; // 切换tab wx.switchTab({ url: taburl, success: () => { that.setData({ selected: data.index }); }, fail: (ex) => { console.log(ex); } }) } }, /** * 组件的生命周期 * https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/lifetimes.html */ lifetimes: { ready: function () { console.log("ready"); } } })