// pages/course/searchCourses/searchCourses.js import { baseUrl, globalImgUrl } from "../../../request"; Page({ /** * 页面的初始数据 */ data: { courseList: [], searchKeyword: '', globalImgUrl, }, // 每次用户输入都会进这里 onSearchInput(e) { this.setData({ searchKeyword: e.detail.value }); }, gotoCourseDetail(e) { const courseId = e.currentTarget.dataset.id; wx.navigateTo({ url: `/pages/course/courseDetail/courseDetail?id=${courseId}`, }); }, onSearch() { const token = wx.getStorageSync('token') const { searchKeyword } = this.data wx.request({ url: baseUrl + '/course/query/keyword', header: { Authorization: token }, method: 'POST', data: { templateString: searchKeyword }, success: res => { let result = res.data.data this.setData({courseList: result}) } }) }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })