Browse Source

小程序day2-pm

大侠 2 năm trước cách đây
mục cha
commit
478379f573

+ 15 - 13
16_miniapp/day-2/code/mini-app/app.js

@@ -1,19 +1,21 @@
 // app.js
 App({
-  onLaunch() {
-    // 展示本地存储能力
-    const logs = wx.getStorageSync('logs') || []
-    logs.unshift(Date.now())
-    wx.setStorageSync('logs', logs)
+  onLaunch(opts) {
+    console.log('小程序初始化完成')
 
-    // 登录
-    wx.login({
-      success: res => {
-        // 发送 res.code 到后台换取 openId, sessionKey, unionId
-      }
-    })
+    console.log(opts)
   },
+  onShow(opts){
+    console.log('小程序 显示')
+    console.log(opts)
+  },
+  onHide(){
+    console.log('小程序 隐藏')
+  },
+  // 定义全局共享数据
   globalData: {
-    userInfo: null
+    shareData: {
+      title: '页面间共享数据'
+    }
   }
-})
+})

+ 6 - 5
16_miniapp/day-2/code/mini-app/app.json

@@ -1,14 +1,15 @@
 {
-  "pages":[
+  "pages": [
+    "pages/result/result",
     "pages/index/index",
     "pages/logs/logs"
   ],
-  "window":{
-    "backgroundTextStyle":"light",
+  "window": {
+    "backgroundTextStyle": "light",
     "navigationBarBackgroundColor": "#fff",
     "navigationBarTitleText": "Weixin",
-    "navigationBarTextStyle":"black"
+    "navigationBarTextStyle": "black"
   },
   "style": "v2",
   "sitemapLocation": "sitemap.json"
-}
+}

+ 4 - 2
16_miniapp/day-2/code/mini-app/pages/index/index.js

@@ -9,6 +9,7 @@ const {
 function add(x, y) {
   return x + y
 }
+console.log('page index')
 Page({
   data: {
     x: 1,
@@ -22,7 +23,7 @@ Page({
     color: 'hotpink',
     fontSize: '20px',
     time: formatTime(new Date()),
-    total: add(x, y)
+    // total: add(x, y)
   },
   onLoad() {
     // var newTime = formatTime(new Date())
@@ -31,7 +32,8 @@ Page({
 
     // this.setData({
     //   time: newTime
-    // })
+    // })、
+    console.log(app.globalData.shareData)
   },
 
 })

+ 1 - 0
16_miniapp/day-2/code/mini-app/pages/logs/logs.js

@@ -1,5 +1,6 @@
 // logs.js
 const util = require('../../utils/util.js')
+console.log('page log')
 
 Page({
   data: {

+ 70 - 0
16_miniapp/day-2/code/mini-app/pages/result/result.js

@@ -0,0 +1,70 @@
+// pages/result.js
+console.log('page result')
+
+const app = getApp()
+
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    msg: app.globalData.shareData.title
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad(options) {
+ console.log('result page loaded')
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady() {
+    console.log('result page ready')
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow() {
+    console.log('result page show')
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide() {
+    console.log('result page hided')
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload() {
+    console.log('result page unloaded')
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh() {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom() {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage() {
+
+  }
+})

+ 3 - 0
16_miniapp/day-2/code/mini-app/pages/result/result.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 5 - 0
16_miniapp/day-2/code/mini-app/pages/result/result.wxml

@@ -0,0 +1,5 @@
+<!--pages/result.wxml-->
+<text>pages/result.wxml</text>
+<view>
+ {{msg}}
+</view>

+ 1 - 0
16_miniapp/day-2/code/mini-app/pages/result/result.wxss

@@ -0,0 +1 @@
+/* pages/result.wxss */