import httpRequestApi from '../../../utils/APIClient'; Page({ data: { allBooks: [] }, onLoad: function (options) { wx.setNavigationBarTitle({ title: '全部课本' }) httpRequestApi.getAllBooks(1, 10).success((res) => { const books = res.data.data.list; const booksTemp = []; books.forEach(item => { let temp = {}; temp.id = item.id; temp.iconImg = item.iconImg; temp.title = item.title.substring(0,5); booksTemp.push(temp); }); this.setData({ allBooks: booksTemp }) console.log(this.data.allBooks) }); }, goToBook: function(e){ console.log(e.currentTarget.dataset) let id = e.currentTarget.dataset.id; let title = e.currentTarget.dataset.title; wx.navigateTo({ url: `../singleBook/singleBook?id=${id}&title=${title}` }) } })