{"id":32039,"date":"2024-11-25T10:14:01","date_gmt":"2024-11-25T02:14:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32039\/"},"modified":"2024-11-25T10:14:01","modified_gmt":"2024-11-25T02:14:01","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f-%e5%bc%95%e7%94%a8%e5%85%b6%e4%bb%96js%e6%96%87%e4%bb%b6%e5%ae%9e%e7%8e%b0%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32039\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u5f15\u7528\u5176\u4ed6js\u6587\u4ef6\u5b9e\u73b0\u4ee3\u7801"},"content":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86\u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u5f15\u7528\u5176\u4ed6js\u6587\u4ef6\u5b9e\u73b0\u4ee3\u7801\u7684\u76f8\u5173\u8d44\u6599,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b<\/p>\n<p><strong>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5982\u4f55\u5f15\u7528\u5176\u4ed6js\u6587\u4ef6<\/strong><\/p>\n<p>1.\u6211\u4eec\u5148\u5efa\u7acb\u4e00\u4e2acommon.js\u6587\u4ef6\uff0c\u5728common.js\u7f16\u5199\u6211\u4eec\u7684\u7a0b\u5e8f\uff0c<\/p>\n<\/p>\n<pre>function&nbsp;myfunc()&nbsp;{\nconsole.log(\"myfunc....\");\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"color: #0000ff\">module.exports.myfunc = myfunc; \u8fd9\u6837\u66b4\u9732\u63a5\u53e3\uff0c\u8fd9\u91cc\u4e0d\u66b4\u9732\u662f\u4e0d\u80fd\u5f15\u7528\u7684\uff0c<\/span><\/p>\n<p><strong>\u5728\u6587\u4ef6\u57dfjs\u5185<\/strong><\/p>\n<p><span style=\"color: #0000ff\">var common = require(&#8220;..\/..\/common.js&#8221;);\u53bb\u94fe\u63a5\u8fc7\u6765\uff0c\u5149\u94fe\u63a5\u8fc7\u6765\u8fd8\u4e0d\u884c\uff01<\/span><\/p>\n<\/p>\n<pre>\n\n&nbsp;\n\n&nbsp;var&nbsp;app;\nvar&nbsp;common&nbsp;=&nbsp;require(\"..\/..\/common.js\");\nPage({\ndata:{\n\n},\nonLoad:function()&nbsp;{\napp&nbsp;=&nbsp;getApp();\nthis.setData({version:app.globalData.appName});\ncommon.myfunc();&nbsp;\/\/\u6700\u540e\u6211\u4eec\u9700\u8981\u6267\u884c\u624d\u80fd\u751f\u6548\uff01\n}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff0c\u66f4\u591a\u76f8\u5173\u5185\u5bb9\u8bf7\u5173\u6ce8PHP\u4e2d\u6587\u7f51\uff01<\/p>\n<p>\u76f8\u5173\u63a8\u8350\uff1a<\/p>\n<p><\/p>\n<p><\/p>\n<\/p>\n<p><span><\/span><\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u5f15\u7528\u5176\u4ed6js\u6587\u4ef6\u5b9e\u73b0\u4ee3\u7801\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 \u5f15\u7528\u5176\u4ed6js\u6587\u4ef6\u5b9e\u73b0\u4ee3\u7801\u7684\u76f8\u5173\u8d44\u6599,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b \u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5982\u4f55\u5f15\u7528\u5176\u4ed6js\u6587\u4ef6 1.\u6211\u4eec\u5148\u5efa\u7acb\u4e00\u4e2acommon.js\u6587\u4ef6\uff0c\u5728common.js\u7f16\u5199\u6211\u4eec\u7684\u7a0b\u5e8f\uff0c function&nbsp;myfunc()&nbsp;{ console.log(&#8220;myfunc&#8230;.&#8221;); } \u767b\u5f55\u540e\u590d\u5236 module.exports.myfunc = myfunc; \u8fd9\u6837\u66b4\u9732\u63a5\u53e3\uff0c\u8fd9\u91cc\u4e0d\u66b4\u9732\u662f\u4e0d\u80fd\u5f15\u7528\u7684\uff0c \u5728\u6587\u4ef6\u57dfjs\u5185 var common = require(&#8220;..\/..\/common.js&#8221;);\u53bb\u94fe\u63a5\u8fc7\u6765\uff0c\u5149\u94fe\u63a5\u8fc7\u6765\u8fd8\u4e0d\u884c\uff01 &nbsp; &nbsp;var&nbsp;app; var&nbsp;common&nbsp;=&nbsp;require(&#8220;..\/..\/common.js&#8221;); Page({ data:{ }, onLoad:function()&nbsp;{ app&nbsp;=&nbsp;getApp(); this.setData({version:app.globalData.appName}); common.myfunc();&nbsp;\/\/\u6700\u540e\u6211\u4eec\u9700\u8981\u6267\u884c\u624d\u80fd\u751f\u6548\uff01 } }) \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff0c\u66f4\u591a\u76f8\u5173\u5185\u5bb9\u8bf7\u5173\u6ce8PHP\u4e2d\u6587\u7f51\uff01 \u76f8\u5173\u63a8\u8350\uff1a \u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u5f15\u7528\u5176\u4ed6js\u6587\u4ef6\u5b9e\u73b0\u4ee3\u7801\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-32039","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32039","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=32039"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32039\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}