contact.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // pages/contact/contact.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. colorList: [],
  8. isloding: false
  9. },
  10. getColors() {
  11. this.setData({
  12. isloding: true
  13. })
  14. // 需要展示 loading 效果
  15. wx.showLoading({
  16. title: '数据加载中...'
  17. })
  18. wx.request({
  19. url: 'https://www.escook.cn/api/color',
  20. method: 'get',
  21. success: ({ data: res }) => {
  22. this.setData({
  23. colorList: [...this.data.colorList, ...res.data]
  24. })
  25. },
  26. complete: () => {
  27. wx.hideLoading()
  28. this.setData({
  29. isloding: false
  30. })
  31. }
  32. })
  33. },
  34. /**
  35. * 生命周期函数--监听页面加载
  36. */
  37. onLoad: function (options) {
  38. this.getColors()
  39. },
  40. /**
  41. * 生命周期函数--监听页面初次渲染完成
  42. */
  43. onReady: function () {
  44. },
  45. /**
  46. * 生命周期函数--监听页面显示
  47. */
  48. onShow: function () {
  49. },
  50. /**
  51. * 生命周期函数--监听页面隐藏
  52. */
  53. onHide: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面卸载
  57. */
  58. onUnload: function () {
  59. },
  60. /**
  61. * 页面相关事件处理函数--监听用户下拉动作
  62. */
  63. onPullDownRefresh: function () {
  64. },
  65. /**
  66. * 页面上拉触底事件的处理函数
  67. */
  68. onReachBottom: function () {
  69. if (this.data.isloding) return
  70. this.getColors()
  71. },
  72. /**
  73. * 用户点击右上角分享
  74. */
  75. onShareAppMessage: function () {
  76. }
  77. })