movie.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // pages/movie/movie.js
  2. const {
  3. default: Toast
  4. } = require("@vant/weapp/toast/toast");
  5. const axios = require("axios-miniprogram").default;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. movieList: [],
  12. start: 0,
  13. count: 10
  14. },
  15. init: function () {
  16. const toast =
  17. // 自定义加载图标
  18. Toast.loading({
  19. message: '加载中...',
  20. forbidClick: true,
  21. });
  22. axios.get("http://localhost:4000/movie/list", {
  23. start: this.data.movieList.length,
  24. count: this.data.count
  25. }).then(res => {
  26. this.setData({
  27. movieList: [...this.data.movieList,...res.data.subject_collection_items]
  28. })
  29. Toast.clear();
  30. }).catch(err => {
  31. console.log("失败")
  32. })
  33. },
  34. goDetail:function(event) {
  35. console.log("执行",event.target.dataset.movieid)
  36. wx.navigateTo({
  37. url: `/pages/detail/detail?id=${event.target.dataset.movieid}`
  38. })
  39. },
  40. /**
  41. * 生命周期函数--监听页面加载
  42. */
  43. onLoad(options) {
  44. this.init();
  45. },
  46. /**
  47. * 生命周期函数--监听页面初次渲染完成
  48. */
  49. onReady() {
  50. },
  51. /**
  52. * 生命周期函数--监听页面显示
  53. */
  54. onShow() {
  55. },
  56. /**
  57. * 生命周期函数--监听页面隐藏
  58. */
  59. onHide() {
  60. },
  61. /**
  62. * 生命周期函数--监听页面卸载
  63. */
  64. onUnload() {
  65. },
  66. /**
  67. * 页面相关事件处理函数--监听用户下拉动作
  68. */
  69. onPullDownRefresh() {
  70. this.init();
  71. },
  72. /**
  73. * 页面上拉触底事件的处理函数
  74. */
  75. onReachBottom() {
  76. this.init()
  77. },
  78. /**
  79. * 用户点击右上角分享
  80. */
  81. onShareAppMessage() {
  82. }
  83. })