home.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // pages/home/home.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. },
  8. // 发起GET数据请求
  9. getInfo() {
  10. wx.request({
  11. url: 'https://www.escook.cn/api/get',
  12. method: 'GET',
  13. data: {
  14. name: 'zs',
  15. age: 20
  16. },
  17. success: (res) => {
  18. console.log(res.data)
  19. }
  20. })
  21. },
  22. // 发起POST请求
  23. postInfo() {
  24. wx.request({
  25. url: 'https://www.escook.cn/api/post',
  26. method: "POST",
  27. data: {
  28. name: 'ls',
  29. age: 33
  30. },
  31. success: (res) => {
  32. console.log(res.data)
  33. }
  34. })
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad: function (options) {
  40. this.getInfo()
  41. this.postInfo()
  42. },
  43. /**
  44. * 生命周期函数--监听页面初次渲染完成
  45. */
  46. onReady: function () {
  47. },
  48. /**
  49. * 生命周期函数--监听页面显示
  50. */
  51. onShow: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面隐藏
  55. */
  56. onHide: function () {
  57. },
  58. /**
  59. * 生命周期函数--监听页面卸载
  60. */
  61. onUnload: function () {
  62. },
  63. /**
  64. * 页面相关事件处理函数--监听用户下拉动作
  65. */
  66. onPullDownRefresh: function () {
  67. },
  68. /**
  69. * 页面上拉触底事件的处理函数
  70. */
  71. onReachBottom: function () {
  72. },
  73. /**
  74. * 用户点击右上角分享
  75. */
  76. onShareAppMessage: function () {
  77. }
  78. })