const types = ['default', 'primary', 'warn'] const pageObject = { data: { theme: 'light', defaultSize: 'default', primarySize: 'default', warnSize: 'default', disabled: false, plain: false, loading: false, canIUseGetUserProfile: false }, onShareAppMessage() { return { title: 'button', path: 'packageComponent/pages/form/button/button' } }, setDisabled() { this.setData({ disabled: !this.data.disabled }) }, setPlain() { this.setData({ plain: !this.data.plain }) }, setLoading() { this.setData({ loading: !this.data.loading }) }, handleContact(e) { console.log(e.detail) }, handleGetPhoneNumber(e) { console.log(e.detail) }, handleOpenSetting(e) { console.log(e.detail.authSetting) }, handleGetUserInfo(e) { console.log('getUserInfo: ', e.detail.userInfo) }, handleGetUserProfile(e) { wx.getUserProfile({ desc: '用于演示 wx.getUserProfile', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { console.log('wx.getUserProfile: ', res.userInfo) } }) }, onLoad() { this.setData({ theme: wx.getSystemInfoSync().theme || 'light' }) if (wx.onThemeChange) { wx.onThemeChange(({theme}) => { this.setData({theme}) }) } if (wx.getUserProfile) { this.setData({ canIUseGetUserProfile: true }) } } } for (let i = 0; i < types.length; ++i) { (function (type) { pageObject[type] = function () { const key = `${type}Size` const changedData = {} changedData[key] = this.data[key] === 'default' ? 'mini' : 'default' this.setData(changedData) } }(types[i])) } Page(pageObject)