Page({ /** * 页面的初始数据 */ data: { current: '1', dataUrl: [ 'https://easy-mock.com/mock/5c9c6cad45252c38c9a09ca1/example/smallApp', 'https://easy-mock.com/mock/5c9c6cad45252c38c9a09ca1/example/smallApp' ], dataList: [], isHaveData: false, isHaveMore: true }, changeTab: function({ detail }) { // tab切换 this.setData({ current: detail.key, dataList: [] }) // this.getDataList() }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // this.getDataList() }, getDataList: function() { var that = this wx.showLoading({ title: '加载中', mask: true }) wx.request({ url: that.data.dataUrl[that.data.current - 1], method: 'get', dataType: 'json', success: function(res) { if (res.data.code == 0) { let list = res.data.data wx.hideLoading() list.map(item => { if (item.desc.length > 60) { item.isCut = true item.showText = '查看更多' item.cutDesc = item.desc.slice(0, 60) + '...' } else { item.cutDesc = item.desc } }) that.setData({ dataList: that.data.dataList.concat(list) }) } } }) }, showAllDesc: function(e) { let newList = this.data.dataList newList.map(item => { if (item.showText == '查看更多') { item.cutDesc = item.desc item.showText = '收回' } else if (item.showText == '收回') { item.cutDesc = item.desc.slice(0, 60) + '...' item.showText = '查看更多' } }) this.setData({ dataList: newList }) } })