加入了搜索功能
This commit is contained in:
@ -1,18 +1,50 @@
|
||||
// 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) {
|
||||
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user