index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //index.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. info: 'hello world',
  8. imgSrc: 'http://www.itheima.com/images/logo.png',
  9. randomNum1: Math.random() * 10,
  10. randomNum2: Math.random().toFixed(2),
  11. count: 0,
  12. msg: '你好,',
  13. type: 1,
  14. flag: true,
  15. arr1: ['苹果', '华为', '小米'],
  16. userList: [
  17. { id: 1, name: '小红' },
  18. { id: 2, name: '小黄' },
  19. { id: 3, name: '小白' }
  20. ]
  21. },
  22. // 定义按钮的事件处理函数
  23. btnTapHandler(e) {
  24. console.log(e)
  25. },
  26. // +1 按钮的点击事件处理函数
  27. CountChange() {
  28. this.setData({
  29. count: this.data.count + 1
  30. })
  31. },
  32. btnTap2(e) {
  33. this.setData({
  34. count: this.data.count + e.target.dataset.info
  35. })
  36. },
  37. // input 输入框的事件处理函数
  38. inputHandler(e) {
  39. // console.log(e.detail.value)
  40. this.setData({
  41. msg: e.detail.value
  42. })
  43. },
  44. /**
  45. * 生命周期函数--监听页面加载
  46. */
  47. onLoad: function (options) {
  48. },
  49. /**
  50. * 生命周期函数--监听页面初次渲染完成
  51. */
  52. onReady: function () {
  53. },
  54. /**
  55. * 生命周期函数--监听页面显示
  56. */
  57. onShow: function () {
  58. },
  59. /**
  60. * 生命周期函数--监听页面隐藏
  61. */
  62. onHide: function () {
  63. },
  64. /**
  65. * 生命周期函数--监听页面卸载
  66. */
  67. onUnload: function () {
  68. },
  69. /**
  70. * 页面相关事件处理函数--监听用户下拉动作
  71. */
  72. onPullDownRefresh: function () {
  73. },
  74. /**
  75. * 页面上拉触底事件的处理函数
  76. */
  77. onReachBottom: function () {
  78. },
  79. /**
  80. * 用户点击右上角分享
  81. */
  82. onShareAppMessage: function () {
  83. }
  84. })