{"id":30797,"date":"2024-11-25T15:46:36","date_gmt":"2024-11-25T07:46:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/30797\/"},"modified":"2024-11-25T15:46:36","modified_gmt":"2024-11-25T07:46:36","slug":"%e5%a6%82%e4%bd%95%e5%b0%86%e5%85%b6%e4%bb%96%e9%a1%b5%e9%9d%a2%e7%9a%84%e6%95%b0%e6%8d%ae%e5%ad%98%e5%85%a5app-js%e4%b8%ad","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/30797\/","title":{"rendered":"\u5982\u4f55\u5c06\u5176\u4ed6\u9875\u9762\u7684\u6570\u636e\u5b58\u5165app.js\u4e2d"},"content":{"rendered":"<p>\/\/\u767b\u5f55\u9875\u9762<\/p>\n<p>Page({<\/p>\n<p>data:{<\/p>\n<p>username:&#8221;,<\/p>\n<p>password:&#8221;<\/p>\n<p>}, onShareAppMessage: function () {<\/p>\n<p>return {<\/p>\n<p>title: &#8216;\u767b\u5f55&#8217;,<\/p>\n<p>desc: &#8216;\u767b\u5f55\u9875\u9762!&#8217;<\/p>\n<p>}<\/p>\n<p>},<\/p>\n<p>onShow:function(){<\/p>\n<p>var that=this;<\/p>\n<p>wx.getStorage({<\/p>\n<p>key: &#8216;username&#8217;,<\/p>\n<p>success: function(res) {<\/p>\n<p>console.log(res.data)<\/p>\n<p>that.setData({<\/p>\n<p>username: res.data<\/p>\n<p>})<\/p>\n<p>},<\/p>\n<p>})<\/p>\n<p>wx.getStorage({<\/p>\n<p>key: &#8216;password&#8217;,<\/p>\n<p>success: function (res) {<\/p>\n<p>console.log(res.data)<\/p>\n<p>that.setData({<\/p>\n<p>password: res.data<\/p>\n<p>})<\/p>\n<p>}<\/p>\n<p>})<\/p>\n<p>},<\/p>\n<p>\/\/app.js<\/p>\n<p>App({<\/p>\n<p>onLaunch: function() {<\/p>\n<p>\/\/\u8c03\u7528API\u4ece\u672c\u5730\u7f13\u5b58\u4e2d\u83b7\u53d6\u6570\u636e<\/p>\n<p>var logs = wx.getStorageSync(&#8216;logs&#8217;) || []<\/p>\n<p>logs.unshift(Date.now())<\/p>\n<p>wx.setStorageSync(&#8216;logs&#8217;, logs)<\/p>\n<p>},<\/p>\n<p>getUserInfo: function(cb) {<\/p>\n<p>var that = this<\/p>\n<p>if (this.globalData.userInfo) {<\/p>\n<p>typeof cb == &#8220;function&#8221; &amp;&amp; cb(this.globalData.userInfo)<\/p>\n<p>} else {<\/p>\n<p>\/\/\u8c03\u7528\u767b\u5f55\u63a5\u53e3<\/p>\n<p>wx.getUserInfo({<\/p>\n<p>withCredentials: false,<\/p>\n<p>success: function(res) {<\/p>\n<p>that.globalData.userInfo = res.userInfo<\/p>\n<p>typeof cb == &#8220;function&#8221; &amp;&amp; cb(that.globalData.userInfo)<\/p>\n<p>}<\/p>\n<p>})<\/p>\n<p>}<\/p>\n<p>},<\/p>\n<p>globalData: {<\/p>\n<p>userInfo: null<\/p>\n<p>},<\/p>\n<p>})<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5c06\u5176\u4ed6\u9875\u9762\u7684\u6570\u636e\u5b58\u5165app.js\u4e2d\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>\/\/\u767b\u5f55\u9875\u9762 Page({ data:{ username:&#8221;, password:&#8221; }, onShareAppMessage: function () { return { title: &#8216;\u767b\u5f55&#8217;, desc: &#8216;\u767b\u5f55\u9875\u9762!&#8217; } }, onShow:function(){ var that=this; wx.getStorage({ key: &#8216;username&#8217;, success: function(res) { console.log(res.data) that.setData({ username: res.data }) }, }) wx.getStorage({ key: &#8216;password&#8217;, success: function (res) { console.log(res.data) that.setData({ password: res.data }) } }) }, \/\/app.js App({ onLaunch: function() { \/\/\u8c03\u7528API\u4ece\u672c\u5730\u7f13\u5b58\u4e2d\u83b7\u53d6\u6570\u636e [&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-30797","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/30797","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=30797"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/30797\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=30797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=30797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=30797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}