look.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // component/look/look.js
  2. import httpRequestApi from '../../utils/APIRequest';
  3. export const lookInit = (that) => {
  4. that.setData({
  5. lookData: {
  6. nav: ['看动画', '学知识', '育儿经'],
  7. lookInd: 0,
  8. lookList: [],
  9. }
  10. })
  11. //点击更改数据
  12. that.lookChoice = ({ currentTarget }) => {
  13. that.data.lookData.lookInd = currentTarget.dataset.index;
  14. that.setData({
  15. lookData: that.data.lookData
  16. })
  17. //数据请求
  18. that.httpList(detail.current + 1)
  19. }
  20. //滑动更改数据
  21. that.lookSlide = ({ detail }) => {
  22. that.data.lookData.lookInd = detail.current;
  23. // console.log(detail.current);
  24. that.setData({
  25. lookData: that.data.lookData
  26. })
  27. that.httpList(detail.current + 1)
  28. }
  29. //跳转到详情页
  30. that.details = ({ currentTarget }) => {
  31. const id = currentTarget.dataset.id;
  32. wx.navigateTo({
  33. url: '/pages/details/details?id=' + id
  34. })
  35. }
  36. //请求数据封装
  37. that.httpList = (ind) => {
  38. httpRequestApi.getCourse({
  39. categoryId: ind
  40. }).success((res)=>{
  41. console.log(res);
  42. that.data.lookData.lookList = res.data.data.list;
  43. that.setData({
  44. lookData: that.data.lookData
  45. })
  46. })
  47. }
  48. //初始数据
  49. that.httpList(1)
  50. }