{"id":28969,"date":"2024-11-25T13:24:50","date_gmt":"2024-11-25T05:24:50","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28969\/"},"modified":"2024-11-25T13:24:50","modified_gmt":"2024-11-25T05:24:50","slug":"%e5%85%b3%e4%ba%8e%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e5%89%8d%e7%ab%af%e6%ba%90%e7%a0%81%e9%80%bb%e8%be%91%e5%92%8c%e5%b7%a5%e4%bd%9c%e6%b5%81%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28969\/","title":{"rendered":"\u5173\u4e8e\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u524d\u7aef\u6e90\u7801\u903b\u8f91\u548c\u5de5\u4f5c\u6d41\u8be6\u89e3"},"content":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u524d\u7aef\u6e90\u7801\u903b\u8f91\u548c\u5de5\u4f5c\u6d41 \u7684\u76f8\u5173\u8d44\u6599,\u672c\u6587\u8fd8\u7ed9\u5927\u5bb6\u63d0\u4f9b\u4e86\u6587\u672c\u57fa\u672c\u7ed3\u6784\u56fe\u548c\u5b9e\u4f8b\u4ee3\u7801\uff0c\u975e\u5e38\u4e0d\u9519\uff0c\u5177\u6709\u53c2\u8003\u501f\u9274\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b<\/p>\n<p>\u5e9f\u8bdd\u4e0d\u591a\u8bf4\uff0c\u76f4\u63a5\u5206\u6790\u524d\u7aef\u4ee3\u7801\u3002<\/p>\n<p>\u6587\u4ef6\u57fa\u672c\u7ed3\u6784\uff1a<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/013\/515b8cfc3ed3ee2cd560c9f1645de1fb-0.png\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u5173\u4e8e\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u524d\u7aef\u6e90\u7801\u903b\u8f91\u548c\u5de5\u4f5c\u6d41\u8be6\u89e3\u63d2\u56fe\" alt=\"\u5173\u4e8e\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u524d\u7aef\u6e90\u7801\u903b\u8f91\u548c\u5de5\u4f5c\u6d41\u8be6\u89e3\u63d2\u56fe\" \/><\/p>\n<p>\u5148\u770b\u5165\u53e3app.\uff0capp(obj)\u6ce8\u518c\u4e00\u4e2a\u5c0f\u7a0b\u5e8f\u3002\u63a5\u53d7\u4e00\u4e2a  \u53c2\u6570\uff0c\u5176\u6307\u5b9a\u5c0f\u7a0b\u5e8f\u7684\u7b49\u3002\u5176\u4ed6\u6587\u4ef6\u53ef\u4ee5\u901a\u8fc7\u5168\u5c40\u65b9\u6cd5getApp()\u83b7\u53d6app\u5b9e\u4f8b\uff0c\u8fdb\u800c\u76f4\u63a5\u8c03\u7528\u5b83\u7684\u6216\u65b9\u6cd5\uff0c\u4f8b\u5982\uff08getApp().globalData\uff09<\/p>\n<\/p>\n<pre>\/\/app.js\r\nApp({\r\nonLaunch:&nbsp;function&nbsp;()&nbsp;{\r\n\/\/\u8c03\u7528API\u4ece\u672c\u5730\u7f13\u5b58\u4e2d\u83b7\u53d6\u6570\u636e\r\nvar&nbsp;logs&nbsp;=&nbsp;wx.getStorageSync('logs')&nbsp;||&nbsp;[]\r\nlogs.unshift(Date.now())\r\nwx.setStorageSync('logs',&nbsp;logs)\r\n},\r\ngetUserInfo:function(cb){\r\nvar&nbsp;that&nbsp;=&nbsp;this\r\nif(this.globalData.userInfo){\r\ntypeof&nbsp;cb&nbsp;==&nbsp;\"function\"&nbsp;&amp;amp;&amp;amp;&nbsp;cb(this.globalData.userInfo)\r\n}else{\r\n\/\/\u8c03\u7528\u767b\u5f55\u63a5\u53e3\r\nwx.login({\r\nsuccess:&nbsp;function&nbsp;()&nbsp;{\r\nwx.getUserInfo({\r\nsuccess:&nbsp;function&nbsp;(res)&nbsp;{\r\nthat.globalData.userInfo&nbsp;=&nbsp;res.userInfo\r\ntypeof&nbsp;cb&nbsp;==&nbsp;\"function\"&nbsp;&amp;amp;&amp;amp;&nbsp;cb(that.globalData.userInfo)\r\n}\r\n})\r\n}\r\n})\r\n}\r\n},\r\nglobalData:{\r\nuserInfo:null\r\n}\r\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u6211\u7406\u89e3app.js\u4e3a\u5165\u53e3\u521d\u59cb\u5316\u6587\u4ef6\uff0c\u4e5f\u662f\u63d0\u4f9b\u5168\u5c40API\u62d3\u5c55\u7684\u5730\u65b9\u3002\u4e0b\u8fb9\u5206\u6790\u4e0b\u81ea\u5e26\u7684\u51e0\u4e2a\u65b9\u6cd5\u548c\u5c5e\u6027<\/p>\n<p>onLaunch\u94a9\u5b50\u51fd\u6570\u4f1a\u5728\u5c0f\u7a0b\u5e8f\u521d\u59cb\u5316\u5b8c\u6210\u540e\u4f1a\u81ea\u52a8\u6267\u884c\u4e00\u6b21\uff0c\u7136\u540e\u5728\u5c0f\u7a0b\u5e8f\u751f\u547d\u5468\u671f\u91cc\u5982\u679c\u4f60\u4e0d\u4e3b\u52a8\u8c03\u7528onLaunch\uff0c\u5b83\u5c31\u4e0d\u4f1a\u5728\u6267\u884c\u3002<\/p>\n<p>var logs = wx.getStorageSync(&#8216;logs&#8217;) || []\u83b7\u53d6\u672c\u5730\u7f13\u5b58\u4e2d\u7684logs\u5c5e\u6027\uff0c\u5982\u679c\u503c\u4e3a\u7a7a\uff0c\u90a3\u4e48\u8bbe\u7f6elogs=[] \u4e0e\u4e2d\u7684localStorage\u4f5c\u7528\u76f8\u4f3clogs.unshift(Date.now()) \u5f53\u524d\u767b\u5f55\u65f6\u95f4\u6dfb\u52a0\u5230\u4e2dwx.setStorageSync(&#8216;logs&#8217;, logs) \u5c06\u6570\u636e\u5b58\u5165\u672c\u5730\u7f13\u5b58\uff0c\u56e0\u4e3awx\u4e3a\u5168\u5c40\uff0c\u6240\u4ee5\u53ef\u4ee5\u5728\u5176\u4ed6\u6587\u4ef6\u4e2d\u76f4\u63a5\u8c03\u7528wx.getStorageSync(&#8216;logs&#8217;)\u83b7\u53d6\u672c\u5730 <\/p>\n<p>getUserInfo\u51fd\u6570\uff0c\u987e\u540d\u601d\u4e49\u5c31\u662f\u83b7\u53d6\u767b\u5f55\u7528\u6237\u4fe1\u606f\uff0c\u76f8\u5f53\u4e8e\u6b64\u51fd\u6570\u63d0\u4f9b\u4e86\u83b7\u53d6\u7528\u6237\u4fe1\u606f\u7684\u63a5\u53e3\uff0c\u5176\u4ed6\u9875\u9762\u4e0d\u8c03\u7528\u81ea\u7136\u4e0d\u4f1a\u6267\u884c\u3002\u5176\u4ed6\u9875\u9762\u901a\u8fc7getApp().getUserInfo(function(userinfo){console.log(userinfo);})\u8fd9\u79cd\u65b9\u5f0f\u8c03\u7528\u8be5\u65b9\u6cd5\uff0c\u83b7\u53d6\u7528\u6237\u4fe1\u606f\u3002<\/p>\n<\/p>\n<pre>getUserInfo:function(cb){\/\/\u53c2\u6570\u4e3acb,\u7c7b\u578b\u4e3a\u51fd\u6570\r\nvar&nbsp;that&nbsp;=&nbsp;this\r\nif(this.globalData.userInfo){\/\/\u7528\u6237\u4fe1\u606f\u4e0d\u4e3a\u7a7a\r\ntypeof&nbsp;cb&nbsp;==&nbsp;\"function\"&nbsp;&amp;amp;&amp;amp;&nbsp;cb(this.globalData.userInfo)\/\/\u5982\u679c\u53c2\u6570cb\u7684\u7c7b\u578b\u4e3a\u51fd\u6570\uff0c\u90a3\u4e48\u6267\u884ccb,\u83b7\u53d6\u7528\u6237\u4fe1\u606f\uff1b\r\n}else{\/\/\u5982\u679c\u7528\u6237\u4fe1\u606f\u4e3a\u7a7a\uff0c\u4e5f\u5c31\u662f\u8bf4\u7b2c\u4e00\u6b21\u8c03\u7528getUserInfo\uff0c\u4f1a\u8c03\u7528\u7528\u6237\u767b\u5f55\u63a5\u53e3\u3002\r\nwx.login({\r\nsuccess:&nbsp;function&nbsp;()&nbsp;{\r\nwx.getUserInfo({\r\nsuccess:&nbsp;function&nbsp;(res)&nbsp;{\r\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000&nbsp;console.log(res)\r\nthat.globalData.userInfo&nbsp;=&nbsp;res.userInfo\/\/\u628a\u7528\u6237\u4fe1\u606f\u8d4b\u7ed9globalData\uff0c\u5982\u679c\u518d\u6b21\u8c03\u7528getUserInfo\u51fd\u6570\u7684\u65f6\u5019\uff0c\u4e0d\u9700\u8981\u8c03\u7528\u767b\u5f55\u63a5\u53e3\r\ntypeof&nbsp;cb&nbsp;==&nbsp;\"function\"&nbsp;&amp;amp;&amp;amp;&nbsp;cb(that.globalData.userInfo)\/\/\u5982\u679c\u53c2\u6570cb\u7c7b\u578b\u4e3a\u51fd\u6570\uff0c\u6267\u884ccb,\u83b7\u53d6\u7528\u6237\u4fe1\u606f\r\n}\r\n})\r\n}\r\n})\r\n}\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>globalData\u5bf9\u8c61\u7528\u6765\u5b58\u50a8\u5168\u5c40\u6570\u636e\uff0c\u5728\u5176\u4ed6\u5730\u65b9\u8c03\u7528<\/p>\n<p>\u7136\u540e\u7b80\u8981\u5206\u6790\u4e0bapp.\u6587\u4ef6,\u8be5\u6587\u4ef6\u4f5c\u7528\u662f\u5bf9\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u8fdb\u884c\u5168\u5c40\u914d\u7f6e\uff0c\u51b3\u5b9a\u9875\u9762\u6587\u4ef6\u7684\u8def\u5f84\u3001\u7a97\u53e3\u8868\u73b0\u3001\u8bbe\u7f6e\u7f51\u7edc\u8d85\u65f6\u65f6\u95f4\u3001\u8bbe\u7f6e\u591a tab \u7b49\u3001<\/p>\n<p>\u3000\u3000\u6700\u91cd\u8981\u7684\u662fpages\u5c5e\u6027\uff0c\u5fc5\u586b\uff0c\u4e3a\u6570\u7ec4\uff0c\u6570\u7ec4\u5185\u7684\u5143\u7d20\u4e3a\u6027\u6587\u4ef6\u8def\u5f84\uff0c\u6307\u5b9a\u5c0f\u7a0b\u5e8f\u7531\u54ea\u4e9b\u9875\u9762\u7ec4\u6210\uff0c\u7b2c\u4e00\u9879\u5fc5\u987b\u662f\u5c0f\u7a0b\u5e8f\u521d\u59cb\u9875\u9762\u3002<\/p>\n<\/p>\n<pre>{\r\n\"pages\":[\r\n\"pages\/index\/index\",\r\n\"pages\/logs\/logs\"\r\n],\r\n\"window\":{\r\n\"backgroundTextStyle\":\"light\",\r\n\"navigationBarBackgroundColor\":&nbsp;\"#fff\",\r\n\"navigationBarTitleText\":&nbsp;\"WeChat\",\r\n\"navigationBarTextStyle\":\"black\"\r\n}\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u7136\u540e\u6765\u770b\u4e0b\u9879\u76eeindex\u548clogs\u6587\u4ef6\u5939\u3002\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u521d\u59cb\u9879\u76ee\u628a\u6bcf\u4e2a\u9875\u9762\u76f8\u5173\u7684js\u3001\u3001w\u653e\u5728\u5404\u81ea\u7684\u6587\u4ef6\uff0c\u8fd9\u6837\u770b\u8d77\u6765\u7ed3\u6784\u6e05\u6670\u660e\u6717\u5f88\u591a\u3002<\/p>\n<p>\u3000\u3000\u5148\u6765\u770bindex\u6587\u4ef6\u5939\uff0c\u5373\u5c0f\u7a0b\u5e8f\u521d\u59cb\u9875\u9762\u3002index\u6587\u4ef6\u5939\u4e0b\u4e3aindex.js\u3001index.wxml\u3001index.wxss\u4e09\u4e2a\u5c0f\u6587\u4ef6\u3002\u5c0f\u7a0b\u5e8f\u628ajs\u3001css\u3001html\u4ee3\u7801\u5206\u79bb\u5f00\u6765\uff0c\u653e\u5728\u72ec\u81ea\u7684\u6587\u4ef6\u91cc\uff0c\u5404\u53f8\u5176\u804c\u3002js\u548c\u6837\u5f0f\u8868\u6587\u4ef6\u540d\u5fc5\u987b\u4e0e\u5f53\u524d\u6587\u4ef6\u5939\u7684wxml\u6587\u4ef6\u540d\u4fdd\u6301\u4e00\u81f4\uff0c\u8fd9\u6837\u624d\u80fd\u4fdd\u8bc1js\u548c\u6837\u5f0f\u8868\u7684\u6548\u679c\u80fd\u591f\u5728\u9875\u9762\u4e2d\u663e\u73b0\u51fa\u6765\u3002\u6211\u5f88\u6b23\u8d4f\u8fd9\u6837\u7684\u8bbe\u8ba1\u7406\u5ff5\uff0c\u6574\u9f50\u5212\u4e00\uff0c\u804c\u8d23\u660e\u786e\uff0c\u51cf\u8f7b\u4ee3\u7801\u8bbe\u8ba1\u590d\u6742\u5ea6\u3002<\/p>\n<p>\u3000\u3000index.wxml\uff0c\u8fd9\u5c31\u662f\u5e38\u89c1\u7684\u6a21\u677f\u6587\u4ef6\uff0c\u6570\u636e\uff0c\u6709\u8fc7\u524d\u7aef\u3001mvvm\u9879\u76ee\u5f00\u53d1\u7684\u5bf9\u8fd9\u4e2a\u4e00\u5b9a\u4e0d\u4f1a\u964c\u751f\uff0c\u6bd5\u7adf\u8fd9\u662f\u57fa\u4e8e\u5f00\u53d1\u7684\u3002\u3000\u3000<\/p>\n<\/p>\n<pre>&lt;!--index.wxml--&gt;\r\n&lt;view&gt;\/\/\u89c6\u56fe\u5bb9\u5668\r\n&lt;view&gt;\/\/bindtap\u4e3a\u5bb9\u5668\u7ed1\u5b9a\u70b9\u51fb\u89e6\u6478\u4e8b\u4ef6\uff0c\u5728\u89e6\u6478\u79bb\u5f00\u65f6\u89e6\u53d1bindViewTap\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\uff0cbindViewTap\u901a\u8fc7index.js&nbsp;page()\u8bbe\u7f6e\u6dfb\u52a0\r\n&lt;image&gt;&lt;\/image&gt;\/\/\u5927\u53cc\u62ec\u53f7\u7684\u53d8\u91cf\u6765\u81ea\u4e8eindex.js\u7684data\u5bf9\u8c61\u89e3\u6790\u6210\u5bf9\u5e94\u7684\u503c\uff0c\u800c\u4e14\u662f\u5b9e\u65f6\u7684\r\n&lt;text&gt;{{userInfo.nickName}}&lt;\/text&gt;&lt;\/view&gt;&lt;view&gt;&lt;text&gt;{{motto}}&lt;\/text&gt;&lt;\/view&gt;&lt;\/view&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u3000\u3000index.js\uff0c\u4e0ereaact\u7528\u6cd5\u51e0\u65e0\u4e8c\u5f02\uff0c\u6362\u6c64\u4e0d\u6362\u836f\u3002page()\u6765\u6ce8\u518c\u4e00\u4e2a\u9875\u9762\u3002\u63a5\u53d7\u4e00\u4e2a OBJECT \u53c2\u6570\uff0c\u5176\u6307\u5b9a\u9875\u9762\u7684\u521d\u59cb\u6570\u636e\u3001\u751f\u547d\u5468\u671f\u51fd\u6570\u3001\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u7b49\u3002<\/p>\n<\/p>\n<pre>var&nbsp;app&nbsp;=&nbsp;getApp()&nbsp;\/\/&nbsp;\u83b7\u53d6\u5165\u53e3\u6587\u4ef6app\u7684\u5e94\u7528\u5b9e\u4f8b\r\nPage({\r\ndata:&nbsp;{\r\nmotto:&nbsp;'Hello&nbsp;World',\r\nuserInfo:&nbsp;{}\r\n},\r\n\/\/\u81ea\u5b9a\u4e49\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\uff0c\u70b9\u51fb.userinfo\u7684\u5bb9\u6613\u89e6\u53d1\u6b64\u51fd\u6570\r\nbindViewTap:&nbsp;function()&nbsp;{\r\nwx.navigateTo({\/\/\u5168\u5c40\u5bf9\u8c61wx\u7684\u8df3\u8f6c\u9875\u9762\u65b9\u6cd5\r\nurl:&nbsp;'..\/logs\/logs'\r\n})\r\n},\r\nonLoad:&nbsp;function&nbsp;()&nbsp;{\/\/\u53d1\u751f\u9875\u9762\u52a0\u8f7d\u65f6\uff0c\u81ea\u52a8\u89e6\u53d1\u8be5\u751f\u547d\u5468\u671f\u51fd\u6570\r\nconsole.log('onLoad')\r\nvar&nbsp;that&nbsp;=&nbsp;this\r\n\/\/\u8c03\u7528\u5e94\u7528\u5b9e\u4f8b\u7684\u65b9\u6cd5\u83b7\u53d6\u5168\u5c40\u6570\u636e\r\napp.getUserInfo(function(userInfo){\r\n\/\/\u66f4\u65b0\u6570\u636e\uff0c\u9875\u9762\u81ea\u52a8\u6e32\u67d3\r\nthat.setData({\r\nuserInfo:userInfo\r\n})\r\n})\r\n}\r\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u3000\u3000index.wxss\u6587\u4ef6\u53ea\u6e32\u67d3\u5f53\u524d\u6240\u5c5e\u9875\u9762\uff0c\u4f1a\u8986\u76d6\u5168\u5c40app.wxss\u540c\u4e00\u6837\u5f0f\u3002<\/p>\n<p>\u3000 \u518d\u5206\u6790\u4e0blogs\u65e5\u5fd7\u6587\u4ef6\u5939\uff0clogs\u6587\u4ef6\u5939\u4e0b\u4e3alogs.wxml\u3001logs.js\u3001logs.wxss\u3001logs.json\uff0c\u540c\u7406\u4fdd\u8bc1\u540c\u540d\uff0c\u624d\u80fd\u5b8c\u6210\u6548\u679c\u6e32\u67d3\u3002<\/p>\n<p>\u3000 logs.wxml\u6587\u4ef6<\/p>\n<\/p>\n<pre>&lt;!--logs.wxml--&gt;\r\n&lt;view&gt;&lt;block&gt;\/\/block\u5bb9\u5668\u4f5c\u7528\uff0c\u65e0\u5176\u4ed6\u5b9e\u9645\u542b\u4e49\u3002wx:for\u4f5c\u7528\uff1a\u904d\u5386logs\u6570\u7ec4\uff0c\u904d\u5386\u591a\u5c11\u6b21\uff0cblock\u5757\u5c31\u4f1a\u590d\u5236\u591a\u5c11\u6b21\uff0cfor-item\u7b49\u540c\u4e8e\u4e3a&lt;br&gt;\u904d\u5386\u5143\u7d20\u8d77\u4e00\u4e2a\u53d8\u91cf\u540d\uff0c\u65b9\u4fbf\u5f15\u7528\u3002&lt;br&gt;&lt;text&gt;{{index&nbsp;+&nbsp;1}}.&nbsp;{{log}}&lt;\/text&gt;&lt;\/block&gt;&lt;\/view&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u3000\u3000logs.js \u6587\u4ef6<\/p>\n<\/p>\n<pre>\/\/logs.js\r\nvar&nbsp;util&nbsp;=&nbsp;require('..\/..\/utils\/util.js')&nbsp;\/\/util.js\u76f8\u5f53\u4e8e\u4e00\u4e2a\u51fd\u6570\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u8fd9\u4e2a\u6587\u4ef6\u5185\u81ea\u5b9a\u4e49\u6269\u5c55\u548c\u5c01\u88c5\u4e00\u4e9b\u5e38\u7528\u7684\u51fd\u6570\u548c\u65b9\u6cd5\r\nPage({\r\ndata:&nbsp;{\r\nlogs:&nbsp;[]\r\n},\r\nonLoad:&nbsp;function&nbsp;()&nbsp;{\r\nthis.setData({\r\nlogs:&nbsp;(wx.getStorageSync('logs')&nbsp;||&nbsp;[]).map(function&nbsp;(log)&nbsp;{\/\/\u901a\u8fc7wx.getStorageSync\u83b7\u53d6\u672c\u5730\u7f13\u5b58\u7684logs\u65e5\u5fd7\u6570\u636e\r\nreturn&nbsp;util.formatTime(new&nbsp;Date(log))\/\/\u65e5\u671f\u683c\u5f0f\u5316\r\n})\r\n})\r\n}\r\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u3000\u3000logs.json\u6587\u4ef6<\/p>\n<\/p>\n<pre>{\r\n\"navigationBarTitleText\":&nbsp;\"\u67e5\u770b\u542f\u52a8\u65e5\u5fd7\"&nbsp;\/\/\u5f53\u524d\u9875\u9762\u914d\u7f6e\u6587\u4ef6\uff0c\u8bbe\u7f6ewindow\u5f53\u524d\u9875\u9762\u9876\u90e8\u5bfc\u822a\u680f\u6807\u9898\u7b49\u76f8\u5173\u5185\u5bb9\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u57fa\u672c\u9875\u9762\u7ed3\u6784\u548c\u903b\u8f91\u5c31\u8fd9\u4e48\u7b80\u5355\uff0c\u66b4\u9732\u7ed9\u6211\u4eec\u7684\u6ca1\u6709\u4e00\u70b9\u4ee4\u4eba\u8d39\u89e3\u7684\u4e1c\u897f\u3002<\/p>\n<p>\u5c0f\u7a0b\u5e8f\u8fd8\u63d0\u4f9b\u4e86\u5f88\u591a\u5b98\u65b9\u7ec4\u4ef6\u548cAPI\u7b49\u5f85\u6211\u4eec\u6df1\u6316\uff0c\u52a0\u6cb9\u5427\uff0c\u5c11\u5e74\uff01\u5c0f\u7a0b\u5e8f\u5b98\u65b9\u6587\u6863\u5730\u5740<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5173\u4e8e\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u524d\u7aef\u6e90\u7801\u903b\u8f91\u548c\u5de5\u4f5c\u6d41\u8be6\u89e3\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u524d\u7aef\u6e90\u7801\u903b\u8f91\u548c\u5de5\u4f5c\u6d41 \u7684\u76f8\u5173\u8d44\u6599,\u672c\u6587\u8fd8\u7ed9\u5927\u5bb6\u63d0\u4f9b\u4e86\u6587\u672c\u57fa\u672c\u7ed3\u6784\u56fe\u548c\u5b9e\u4f8b\u4ee3\u7801\uff0c\u975e\u5e38\u4e0d\u9519\uff0c\u5177\u6709\u53c2\u8003\u501f\u9274\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b \u5e9f\u8bdd\u4e0d\u591a\u8bf4\uff0c\u76f4\u63a5\u5206\u6790\u524d\u7aef\u4ee3\u7801\u3002 \u6587\u4ef6\u57fa\u672c\u7ed3\u6784\uff1a \u5148\u770b\u5165\u53e3app.\uff0capp(obj)\u6ce8\u518c\u4e00\u4e2a\u5c0f\u7a0b\u5e8f\u3002\u63a5\u53d7\u4e00\u4e2a \u53c2\u6570\uff0c\u5176\u6307\u5b9a\u5c0f\u7a0b\u5e8f\u7684\u7b49\u3002\u5176\u4ed6\u6587\u4ef6\u53ef\u4ee5\u901a\u8fc7\u5168\u5c40\u65b9\u6cd5getApp()\u83b7\u53d6app\u5b9e\u4f8b\uff0c\u8fdb\u800c\u76f4\u63a5\u8c03\u7528\u5b83\u7684\u6216\u65b9\u6cd5\uff0c\u4f8b\u5982\uff08getApp().globalData\uff09 \/\/app.js App({ onLaunch:&nbsp;function&nbsp;()&nbsp;{ \/\/\u8c03\u7528API\u4ece\u672c\u5730\u7f13\u5b58\u4e2d\u83b7\u53d6\u6570\u636e var&nbsp;logs&nbsp;=&nbsp;wx.getStorageSync(&#8216;logs&#8217;)&nbsp;||&nbsp;[] logs.unshift(Date.now()) wx.setStorageSync(&#8216;logs&#8217;,&nbsp;logs) }, getUserInfo:function(cb){ var&nbsp;that&nbsp;=&nbsp;this if(this.globalData.userInfo){ typeof&nbsp;cb&nbsp;==&nbsp;&#8220;function&#8221;&nbsp;&amp;amp;&amp;amp;&nbsp;cb(this.globalData.userInfo) }else{ \/\/\u8c03\u7528\u767b\u5f55\u63a5\u53e3 wx.login({ success:&nbsp;function&nbsp;()&nbsp;{ wx.getUserInfo({ success:&nbsp;function&nbsp;(res)&nbsp;{ that.globalData.userInfo&nbsp;=&nbsp;res.userInfo typeof&nbsp;cb&nbsp;==&nbsp;&#8220;function&#8221;&nbsp;&amp;amp;&amp;amp;&nbsp;cb(that.globalData.userInfo) } }) } }) } }, globalData:{ userInfo:null } }) \u767b\u5f55\u540e\u590d\u5236 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u6211\u7406\u89e3app.js\u4e3a\u5165\u53e3\u521d\u59cb\u5316\u6587\u4ef6\uff0c\u4e5f\u662f\u63d0\u4f9b\u5168\u5c40API\u62d3\u5c55\u7684\u5730\u65b9\u3002\u4e0b\u8fb9\u5206\u6790\u4e0b\u81ea\u5e26\u7684\u51e0\u4e2a\u65b9\u6cd5\u548c\u5c5e\u6027 onLaunch\u94a9\u5b50\u51fd\u6570\u4f1a\u5728\u5c0f\u7a0b\u5e8f\u521d\u59cb\u5316\u5b8c\u6210\u540e\u4f1a\u81ea\u52a8\u6267\u884c\u4e00\u6b21\uff0c\u7136\u540e\u5728\u5c0f\u7a0b\u5e8f\u751f\u547d\u5468\u671f\u91cc\u5982\u679c\u4f60\u4e0d\u4e3b\u52a8\u8c03\u7528onLaunch\uff0c\u5b83\u5c31\u4e0d\u4f1a\u5728\u6267\u884c\u3002 var logs = wx.getStorageSync(&#8216;logs&#8217;) || []\u83b7\u53d6\u672c\u5730\u7f13\u5b58\u4e2d\u7684logs\u5c5e\u6027\uff0c\u5982\u679c\u503c\u4e3a\u7a7a\uff0c\u90a3\u4e48\u8bbe\u7f6elogs=[] \u4e0e\u4e2d\u7684localStorage\u4f5c\u7528\u76f8\u4f3clogs.unshift(Date.now()) \u5f53\u524d\u767b\u5f55\u65f6\u95f4\u6dfb\u52a0\u5230\u4e2dwx.setStorageSync(&#8216;logs&#8217;, logs) \u5c06\u6570\u636e\u5b58\u5165\u672c\u5730\u7f13\u5b58\uff0c\u56e0\u4e3awx\u4e3a\u5168\u5c40\uff0c\u6240\u4ee5\u53ef\u4ee5\u5728\u5176\u4ed6\u6587\u4ef6\u4e2d\u76f4\u63a5\u8c03\u7528wx.getStorageSync(&#8216;logs&#8217;)\u83b7\u53d6\u672c\u5730 getUserInfo\u51fd\u6570\uff0c\u987e\u540d\u601d\u4e49\u5c31\u662f\u83b7\u53d6\u767b\u5f55\u7528\u6237\u4fe1\u606f\uff0c\u76f8\u5f53\u4e8e\u6b64\u51fd\u6570\u63d0\u4f9b\u4e86\u83b7\u53d6\u7528\u6237\u4fe1\u606f\u7684\u63a5\u53e3\uff0c\u5176\u4ed6\u9875\u9762\u4e0d\u8c03\u7528\u81ea\u7136\u4e0d\u4f1a\u6267\u884c\u3002\u5176\u4ed6\u9875\u9762\u901a\u8fc7getApp().getUserInfo(function(userinfo){console.log(userinfo);})\u8fd9\u79cd\u65b9\u5f0f\u8c03\u7528\u8be5\u65b9\u6cd5\uff0c\u83b7\u53d6\u7528\u6237\u4fe1\u606f\u3002 getUserInfo:function(cb){\/\/\u53c2\u6570\u4e3acb,\u7c7b\u578b\u4e3a\u51fd\u6570 var&nbsp;that&nbsp;=&nbsp;this if(this.globalData.userInfo){\/\/\u7528\u6237\u4fe1\u606f\u4e0d\u4e3a\u7a7a typeof&nbsp;cb&nbsp;==&nbsp;&#8220;function&#8221;&nbsp;&amp;amp;&amp;amp;&nbsp;cb(this.globalData.userInfo)\/\/\u5982\u679c\u53c2\u6570cb\u7684\u7c7b\u578b\u4e3a\u51fd\u6570\uff0c\u90a3\u4e48\u6267\u884ccb,\u83b7\u53d6\u7528\u6237\u4fe1\u606f\uff1b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-28969","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28969","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=28969"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28969\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28969"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28969"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}