{"id":32407,"date":"2024-11-25T09:58:24","date_gmt":"2024-11-25T01:58:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32407\/"},"modified":"2024-11-25T09:58:24","modified_gmt":"2024-11-25T01:58:24","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8fpage%e6%9e%84%e9%80%a0%e5%87%bd%e6%95%b0%e4%bb%a5%e5%8f%8a%e7%94%9f%e5%91%bd%e5%91%a8%e6%9c%9f%e5%87%bd%e6%95%b0%e7%9a%84%e5%86%85%e5%ae%b9%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32407\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8fPage\u6784\u9020\u51fd\u6570\u4ee5\u53ca\u751f\u547d\u5468\u671f\u51fd\u6570\u7684\u5185\u5bb9\u89e3\u6790\uff08\u9644\u4ee3\u7801\uff09"},"content":{"rendered":"<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5e26\u6765\u7684\u5185\u5bb9\u662f\u5173\u4e8e\u5fae\u4fe1\u5c0f\u7a0b\u5e8fpage\u6784\u9020\u51fd\u6570\u4ee5\u53ca\u751f\u547d\u5468\u671f\u51fd\u6570\u7684\u5185\u5bb9\u89e3\u6790\uff08\u9644\u4ee3\u7801\uff09\uff0c\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u6709\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<p><strong>\u4e00\u3001\u5c06\u516c\u5171\u65b9\u6cd5\u7ed1\u5b9a\u5230Page\u4e0a<\/strong><\/p>\n<p>\u5355\u4e2a\u7ed1\u5b9a<\/p>\n<pre>const oldPage = Page\nPage = function(app) {\n  \/\/ \u6ce8\u610f\u516c\u5171\u51fd\u6570\u7684\u540d\u5b57\u4e0d\u8981\u91cd\u590d\uff0c\u5426\u5219\u8986\u76d6\n  app.util = function() {}\n  \n  return oldPage(app)\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u591a\u4e2a\u7ed1\u5b9a\uff0c\u6587\u4ef6\u7ed1\u5b9a<\/p>\n<pre>const util = require('.\/util.js');  \/\/ \u9700\u8981\u7ed1\u5b9a\u7684\u51fd\u6570\u7531util\u6587\u4ef6exports\u51fa\u6765\nconst oldPage = Page\nPage = function(app) {\n  let newPage = Object.assign({}, util, app)\n  \n  return oldPage(newPage)\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4e8c\u3001\u6269\u5c55\uff0c\u4fee\u6539\u751f\u547d\u5468\u671f\u51fd\u6570<\/strong><\/p>\n<pre>const oldPage = Page\nPage = function(app) {\n  app.onLoad = function(options) { \/\/ \u8fd9\u91cc\u5fc5\u987b\u4f7f\u7528function, \u4e0d\u53ef\u4ee5\u4f7f\u7528\u7bad\u5934\u51fd\u6570\uff0c \u5426\u5219this\u6307\u5411\u9519\u8bef\n      console.log(\"\u6269\u5c55onLoad\");\n  \n      \/\/ onLoad\u51fd\u6570\u5728\u662f\u5f53\u524dpage\u5b9e\u4f8b\u4e0a\u4e0b\u6587\u4e2d\u6267\u884c\uff0c\u6240\u4ee5\u5f53\u524d\u7684this\u4e3a\u5f53\u524dpage\u5b9e\u4f8b\n      \/\/ \u5982\u679c\u4e0d\u4f7f\u7528call\u6765\u786c\u7ed1\u5b9a\uff0c\u800c\u662f\u76f4\u63a5app.onLoad()\uff0c\u90a3\u4e48onLoad\u91cc\u7684this\u5c06\u4e3aapp\u8fd9\u4e2a\u5bf9\u8c61\n      \/\/ \u5373\u6211\u4eec\u6b63\u5e38\u5728page.js\u91ccPage(app) \u62ec\u53f7\u91cc\u9762\u6211\u4eec\u81ea\u5df1\u5199\u7684page\u5bf9\u8c61\n      if(typeof app.onLoad === 'function') {\n          app.onLoad.call(this, options); \n      }\n  }\n  \n  return oldPage(app)\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>ps.\u60f3\u66f4\u7cfb\u7edf\u7684\u4e86\u89e3js\u5173\u4e8ethis\u7684\u77e5\u8bc6\u53ef\u4ee5\u6233\u8fd9\u91cc<\/p>\n<p><strong>\u4e09\u3001\u4f7f\u7528<\/strong><\/p>\n<p>\u6211\u81ea\u5df1\u5199\u7684\u65f6\u5019\uff0c\u5c06\u81ea\u5b9a\u4e49\u7684\u5185\u5bb9\u5355\u72ec\u5c01\u88c5\u5230\u4e00\u4e2ajs\u6587\u4ef6\u4e2d\uff0c\u7136\u540e\u5728app.js\u4e2d\u5f15\u7528\u8fd9\u4e2a\u6587\u4ef6\u5373\u53ef<\/p>\n<pre>require('.\/init.js'); \/\/\u5f15\u7528\u5373\u53ef\nApp({\n  onLaunch: function (options) {\n  }\n\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u76f8\u5173\u63a8\u8350\uff1a<\/p>\n<p><\/p>\n<p><\/p>\n<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8fPage\u6784\u9020\u51fd\u6570\u4ee5\u53ca\u751f\u547d\u5468\u671f\u51fd\u6570\u7684\u5185\u5bb9\u89e3\u6790\uff08\u9644\u4ee3\u7801\uff09\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>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5e26\u6765\u7684\u5185\u5bb9\u662f\u5173\u4e8e\u5fae\u4fe1\u5c0f\u7a0b\u5e8fpage\u6784\u9020\u51fd\u6570\u4ee5\u53ca\u751f\u547d\u5468\u671f\u51fd\u6570\u7684\u5185\u5bb9\u89e3\u6790\uff08\u9644\u4ee3\u7801\uff09\uff0c\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u6709\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002 \u4e00\u3001\u5c06\u516c\u5171\u65b9\u6cd5\u7ed1\u5b9a\u5230Page\u4e0a \u5355\u4e2a\u7ed1\u5b9a const oldPage = Page Page = function(app) { \/\/ \u6ce8\u610f\u516c\u5171\u51fd\u6570\u7684\u540d\u5b57\u4e0d\u8981\u91cd\u590d\uff0c\u5426\u5219\u8986\u76d6 app.util = function() {} return oldPage(app) } \u767b\u5f55\u540e\u590d\u5236 \u591a\u4e2a\u7ed1\u5b9a\uff0c\u6587\u4ef6\u7ed1\u5b9a const util = require(&#8216;.\/util.js&#8217;); \/\/ \u9700\u8981\u7ed1\u5b9a\u7684\u51fd\u6570\u7531util\u6587\u4ef6exports\u51fa\u6765 const oldPage = Page Page = function(app) { let newPage = Object.assign({}, util, app) return oldPage(newPage) } \u767b\u5f55\u540e\u590d\u5236 \u4e8c\u3001\u6269\u5c55\uff0c\u4fee\u6539\u751f\u547d\u5468\u671f\u51fd\u6570 const oldPage = Page Page = function(app) { [&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-32407","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32407","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=32407"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32407\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}