{"id":28783,"date":"2024-11-25T13:27:35","date_gmt":"2024-11-25T05:27:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28783\/"},"modified":"2024-11-25T13:27:35","modified_gmt":"2024-11-25T05:27:35","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e4%b8%ad%e5%a6%82%e4%bd%95%e5%bc%95%e7%94%a8wxml%e6%96%87%e4%bb%b6%e3%80%81%e8%a7%86%e5%9b%be%e6%a8%a1%e7%89%88%e7%9a%84%e4%bd%bf%e7%94%a8%e6%96%b9","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28783\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5"},"content":{"rendered":"<p>\u672c\u6587\u5e26\u5927\u5bb6\u4e86\u89e3\u4e00\u4e0b\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u75282\u79cd\u65b9\u5f0f\u6765\u5f15\u7528wxml\u6587\u4ef6\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5305\u542b\u91cd\u590d\u7684\u5185\u5bb9\uff0c\u8ba9\u7f51\u9875\u5185\u5bb9\u548c\u903b\u8f91\u7ed3\u6784\u66f4\u52a0\u7b80\u5355\u660e\u4e5f\u66f4\u52a0\u8f7b\u91cf\u7ea7\u3002<br \/>\u6b64\u5916\uff0c\u5728\u7b2c\u4e8c\u79cd\u65b9\u6cd5\u4e2d\uff0c\u5927\u5bb6\u53ef\u4ee5\u4e86\u89e3\u5230\uff0c\u7528\u6a21\u677f\u7684\u65b9\u5f0f\u53bb\u5f15\u7528wxml\u6587\u4ef6\u3002<br \/>\u6700\u540e\u518d\u7a0b\u5e8f\u9000\u51fa\u65f6\uff0c\u5982\u4f55\u6e05\u7406\u7684\u65b9\u5f0f\uff0c\u901a\u8fc7\u5c0f\u7a0b\u5e8f\u7684\u751f\u547d\u5468\u671f\u7684\u4ecb\u7ecd\uff0c\u5927\u5bb6\u53ef\u4ee5\u6e05\u695a\u7684\u77e5\u9053\u5c0f\u7a0b\u5e8f\u5728\u5404\u4e2a\u9636\u6bb5\u7684\u4e8b\u4ef6\uff0c\u4ee5\u540e\u9700\u8981\u5728\u4e0d\u540c\u7684\u9636\u6bb5\u5b89\u6392\u6267\u884c\u4e0d\u540c\u7684\u4efb\u52a1\uff0c\u53ef\u4ee5\u5199\u5728\u5bf9\u5e94\u7684\u4e8b\u4ef6\u4e2d\u3002<\/p>\n<p>\u6838\u5fc3\u5185\u5bb9<\/p>\n<p>wxml\u6587\u4ef6\u76842\u79cd\u5f15\u7528\uff08include\u3001import\uff09<\/p>\n<p>\u6a21\u7248\u7684\u4f7f\u7528<\/p>\n<p>\u5c0f\u7a0b\u5e8f\u751f\u547d\u5468\u671f<\/p>\n<p>\u5b9e\u4f8b\u4e00: include\u65b9\u5f0f\u5f15\u7528header.wxml\u6587\u4ef6<\/p>\n<p>\u6587\u4ef6\u5f15\u7528\u5bf9\u4e8e\u4ee3\u7801\u7684\u91cd\u7528\u975e\u5e38\u91cd\u8981\uff0c\u4f8b\u5982\u5728web\u5f00\u53d1\u4e2d\u6211\u4eec\u53ef\u4ee5\u5c06\u516c\u7528\u7684header\u90e8\u5206\u548cfooter\u7b49\u90e8\u5206\u8fdb\u884c\u63d0\u53d6\uff0c\u7136\u540e\u5728\u9700\u8981\u7684\u5730\u65b9\u8fdb\u884c\u5f15\u7528\u3002<br \/>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u91cc\u9762\uff0c\u662f\u5305\u542b\u5f15\u7528\u529f\u80fd\u7684\u2014\u2014include\u3001import\u3002\u8fd9\u4e24\u4e2a\u5f15\u7528\u6587\u4ef6\u7684\u6807\u7b7e\uff0c\u4f7f\u7528\u57fa\u672c\u5dee\u4e0d\u591a\uff0c\u8fd9\u91cc\u5148\u8bf4\u4e00\u4e0binclude\u3002<br \/>\u5fae\u4fe1\u4e2d\u7684\u89c6\u56fe\u6587\u4ef6\u5f15\u7528\uff0c\u5f15\u7528\u8fc7\u6765\u7684\u90fd\u662f\u6ca1\u6709\u6e32\u67d3\u7684\uff0c\u57fa\u672c\u7c7b\u4f3c\u4e8e\u76f4\u63a5\u5c06\u5f15\u7528\u8fc7\u6765\u7684\u6587\u4ef6\u590d\u5236\u5230\u5f15\u7528\u4f4d\u7f6e\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u91cd\u65b0\u5bf9\u5176\u6e32\u67d3\u3002<br \/>\u5b9e\u4f8b\u8bf4\u660e<\/p>\n<p>\u8fd9\u91cc\u5c06\u9ed8\u8ba4\u521b\u5efa\u7684\u7528\u6237\u5934\u50cf\u4fe1\u606f\u63d0\u53d6\u51fa\u5230header.wxml\u4e2d\uff0c\u505a\u4e3a\u5934\u90e8\u5f15\u7528\uff0c\u5206\u522b\u7531index2.wxml\u548cindex3.wxml\u5f15\u7528\uff0c\u5f15\u7528\u65b9\u5f0f\u4e3ainclude\u3002<br \/>\u5b9e\u4f8b\u4ee3\u7801<\/p>\n<p>\u5728pages\u4e2d\u521b\u5efacommon\/header.wxml<br \/>\u4eceindex.wxml\u4e2d\u5c06\u7cfb\u7edf\u9ed8\u8ba4\u521b\u5efa\u7684\u7528\u6237\u4fe1\u606f\u7ed3\u6784\u590d\u5236\u5230header.wxml\u4e2d\u3002<br \/>header.wxml\u4ee3\u7801\uff1a<\/p>\n<pre>&lt;!--pages\/common\/header.wxml--&gt;\r\n&nbsp;&nbsp;&lt;view&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;image&gt;&lt;\/image&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;text&gt;{{userInfo.nickName}}&lt;\/text&gt;\r\n&nbsp;&nbsp;&lt;\/view&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u56e0\u4e3a\u4e24\u4e2a\u9875\u9762\u90fd\u8981\u5305\u542bheader.wxml\uff0c\u6240\u4ee5\u6837\u5f0f\u6587\u4ef6\u5c31\u4e0d\u91cd\u590d\u5199\u4e86\uff0c\u8fd9\u91cc\u76f4\u63a5\u5c06\u6837\u5f0f\u62f7\u8d1d\u5230app.wxss\u3002<br \/>app.wxss\u4ee3\u7801\uff1a<\/p>\n<pre>\/**app.wxss**\/\r\n.userinfo&nbsp;{\r\n&nbsp;&nbsp;display:&nbsp;flex;\r\n&nbsp;&nbsp;flex-direction:&nbsp;column;\r\n&nbsp;&nbsp;align-items:&nbsp;center;\r\n}\r\n&nbsp;\r\n.userinfo-avatar&nbsp;{\r\n&nbsp;&nbsp;width:&nbsp;128rpx;\r\n&nbsp;&nbsp;height:&nbsp;128rpx;\r\n&nbsp;&nbsp;margin:&nbsp;20rpx;\r\n&nbsp;&nbsp;border-radius:&nbsp;50%;\r\n}\r\n&nbsp;\r\n.userinfo-nickname&nbsp;{\r\n&nbsp;&nbsp;color:&nbsp;#aaa;\r\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u521b\u5efaindex\/index2\u548cindex\/index3<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/\/upload\/image\/897\/859\/847\/1489030306713980.jpg\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe\" \/><\/p>\n<p>index2.wxml\u5185\u5bb9\uff1a<\/p>\n<pre>&lt;!--pages\/index\/index2.wxml--&gt;\r\n&lt;view&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;&lt;\/include&gt;\r\n&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;view&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;button&gt;\u8fdb\u5165index3&lt;\/button&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/view&gt;&nbsp;&nbsp;&nbsp;&nbsp;\r\n&lt;\/view&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u56e0\u4e3aindex2.wxml\u548cindex3.wxml\u90fd\u9700\u8981userInfo\u6570\u636e\uff0c\u6240\u4ee5\u8fd9\u8fb9\u5728index2\u83b7\u53d6\u5230\u6570\u636e\u540e\uff0c\u4f7f\u7528\u672c\u5730\u5b58\u50a8\u8fdb\u884c\u5b58\u50a8\uff0cindex3.wxml\u8bfb\u53d6\u672c\u5730\u5b58\u50a8\u3002<\/p>\n<p>index2.js\u4ee3\u7801\uff1a<\/p>\n<pre>\/\/&nbsp;pages\/index\/index2.js\r\nvar&nbsp;app&nbsp;=&nbsp;getApp()\r\n&nbsp;\r\nPage({\r\n&nbsp;&nbsp;data:&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;userInfo:&nbsp;{},\r\n&nbsp;&nbsp;},\r\n&nbsp;\r\n&nbsp;&nbsp;goIndex3:function(){\r\n&nbsp;&nbsp;&nbsp;&nbsp;wx.navigateTo({\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url:&nbsp;'index3'\r\n&nbsp;&nbsp;&nbsp;&nbsp;})\r\n&nbsp;&nbsp;},\r\n&nbsp;\r\n&nbsp;&nbsp;onLoad:&nbsp;function&nbsp;()&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;console.log('onLoad')\r\n&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;that&nbsp;=&nbsp;this\r\n&nbsp;&nbsp;&nbsp;&nbsp;app.getUserInfo(function&nbsp;(userInfo)&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;that.setData({\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userInfo:&nbsp;userInfo\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;})\r\n&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u672c\u5730\u5b58\u50a8\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wx.setStorageSync('userInfo',&nbsp;userInfo)\r\n&nbsp;&nbsp;&nbsp;&nbsp;})\r\n&nbsp;&nbsp;}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>index3.wxml\u4ee3\u7801\uff1a<\/p>\n<pre>&lt;!--pages\/index\/index3.wxml--&gt;\r\n&nbsp;\r\n&lt;view&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;&lt;\/include&gt;\r\n&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;text&gt;pages\/index\/index3.wxml&lt;\/text&gt;&lt;\/view&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>index3.js\u4ee3\u7801\uff1a<\/p>\n<pre>\/\/&nbsp;pages\/index\/index3.js\r\nPage({\r\n&nbsp;&nbsp;data:{\r\n&nbsp;&nbsp;&nbsp;&nbsp;userInfo:&nbsp;{},\r\n&nbsp;&nbsp;},\r\n&nbsp;&nbsp;onLoad:function(options){&nbsp;&nbsp;&nbsp;&nbsp;\r\n&nbsp;&nbsp;&nbsp;&nbsp;this.setData({\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userInfo:&nbsp;wx.getStorageSync('userInfo')\r\n&nbsp;&nbsp;&nbsp;&nbsp;})\r\n&nbsp;&nbsp;},\r\n})<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5b9e\u4f8b\u6548\u679c<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/\/upload\/image\/925\/622\/785\/1489030407897846.gif\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe1\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe1\" \/><\/p>\n<p>\u5b9e\u4f8b\u4e8c: import\u65b9\u5f0f\u5f15\u7528footer.wxml\u6587\u4ef6<\/p>\n<p>\u8fd9\u4e2a\u5b9e\u4f8b\u4f7f\u7528import\u6765\u5f15\u7528\u6587\u4ef6\uff0cimport\u6bd4include\u8981\u5f3a\u5927\u7684\u591a\uff0c\u5f85\u4f1a\u6211\u518d\u5bf9\u4e8e\u8fd9\u4e24\u90fd\u8fdb\u884c\u4e00\u4e0b\u5bf9\u6bd4\u3002<\/p>\n<p>import\u5f15\u7528\u65b9\u5f0f\u6d89\u53ca\u5230\u4e86\u5fae\u4fe1\u7684\u6a21\u7248(template)\uff0c\u8fd9\u91cc\u5148\u8bf4\u4e00\u4e0btemplate\u3002<\/p>\n<p>\u5fae\u4fe1\u89c6\u56fe\u6a21\u7248\uff08template\uff09<\/p>\n<p>template\u4e5f\u662f\u5199\u5728.wxml\u4e2d\uff0c\u7136\u540e\u4f7f\u7528&#8230;\u6807\u8bb0\u6307\u5b9a\u6a21\u7248\u4fe1\u606f\uff0c\u6a21\u7248\u4e0b\u5b9a\u4e49\uff1a<\/p>\n<pre>&lt;template&gt;\r\n&nbsp;&nbsp;&nbsp;&nbsp;\u89c6\u56fe\u4ee3\u7801...\r\n&lt;\/template&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4f7f\u7528name\u5c5e\u6027\uff0c\u4f5c\u4e3a\u6a21\u677f\u7684\u540d\u5b57\u3002<\/p>\n<p>\u4f7f\u7528\u6a21\u7248\uff1a<\/p>\n<pre>&lt;template&gt;&lt;\/template&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>data\u4e3a\u5411\u6a21\u7248\u4f20\u5165\u7684\u6570\u636e\u3002<\/p>\n<p>\u5b9e\u4f8b\u8bf4\u660e<\/p>\n<p>\u4f7f\u7528\u6a21\u7248\u7684\u65b9\u5f0f\u521b\u5efafooter\u89c6\u56fe\u4ee3\u7801\u7247\uff0c\u7136\u540e\u7528import\u548ctemplate\u8fdb\u884c\u4ee3\u7801\u7684\u8c03\u7528\u3002<br \/>\u5b9e\u4f8b\u4ee3\u7801<\/p>\n<p>\u521b\u5efafooter.wxml<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/\/upload\/image\/767\/648\/382\/1489030451302609.jpg\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe2\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe2\" \/><\/p>\n<p>footer.wxml\u4ee3\u7801\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/\/upload\/image\/404\/314\/555\/1489030474376407.jpg\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe3\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe3\" \/><\/p>\n<p>index2.wxml\u4ee3\u7801\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/\/upload\/image\/686\/615\/625\/1489030495712411.jpg\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe4\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe4\" \/><\/p>\n<p>\u5b9e\u4f8b\u6548\u679c<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/\/upload\/image\/669\/690\/544\/1489030512274648.jpg\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe5\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe5\" \/><\/p>\n<p>\u5b9e\u4f8b\u4e09: \u5c0f\u7a0b\u5e8f\u9000\u51fa\u65f6\u6e05\u9664\u672c\u5730\u6570\u636e<\/p>\n<p>\u8fd9\u91cc\u6d89\u53ca\u5230\u4e86\u5c0f\u7a0b\u5e8f\u7684\u751f\u547d\u5468\u671f\u95ee\u9898\uff0c\u53ef\u4ee5\u7c7b\u6bd4\u4e00\u4e0b\u5b89\u5353\u751f\u547d\u5468\u671f\uff0c\u5c0f\u7a0b\u5e8f\u7684\u751f\u547d\u5468\u671f\u5728app.js\u4e2d\u8fdb\u884c\u5b9a\u4e49\uff1a<br \/>[tr] \u5c5e\u6027 \u7c7b\u578b \u63cf\u8ff0 \u89e6\u53d1\u65f6\u673a[\/tr]<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/\/upload\/image\/510\/457\/847\/1489030587864944.png\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe6\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe6\" \/><\/p>\n<p>page\u751f\u547d\u5468\u671f\uff1a<br \/>[tr] \u5c5e\u6027 \u7c7b\u578b \u63cf\u8ff0[\/tr]<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/\/upload\/image\/386\/966\/893\/1489030619827540.png\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe7\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe7\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/\/upload\/image\/670\/454\/158\/1489030631582910.png\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe8\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe8\" \/><\/p>\n<p>\u8fd9\u91cc\u7528\u5230\u4e86onUnload\u4e8b\u4ef6\u3002<br \/>index2.js\u4ee3\u7801\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/\/upload\/image\/950\/170\/904\/1489030655286563.jpg\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe9\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\u63d2\u56fe9\" \/><\/p>\n<p>import\u53ef\u4ee5\u5728\u8be5\u6587\u4ef6\u4e2d\u4f7f\u7528\u76ee\u6807\u6587\u4ef6\u5b9a\u4e49\u7684template<br \/>include\u53ef\u4ee5\u5c06\u76ee\u6807\u6587\u4ef6\u9664\u4e86\u7684\u6574\u4e2a\u4ee3\u7801\u5f15\u5165\uff0c\u76f8\u5f53\u4e8e\u662f\u62f7\u8d1d\u5230include\u4f4d\u7f6e<\/p>\n<p>import\u7684\u4f5c\u7528\u57df<\/p>\n<p>import\u6709\u4f5c\u7528\u57df\u7684\u6982\u5ff5\uff0c\u5373\u53ea\u4f1aimport\u76ee\u6807\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684template\uff0c\u800c\u4e0d\u4f1aimport\u76ee\u6807\u6587\u4ef6import\u7684template\u3002<br \/>\u5982\uff1aC import B\uff0cB import A\uff0c\u5728C\u4e2d\u53ef\u4ee5\u4f7f\u7528B\u5b9a\u4e49\u7684template\uff0c\u5728B\u4e2d\u53ef\u4ee5\u4f7f\u7528A\u5b9a\u4e49\u7684template\uff0c\u4f46\u662fC\u4e0d\u80fd\u4f7f\u7528A\u5b9a\u4e49\u7684template<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\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\u6587\u5e26\u5927\u5bb6\u4e86\u89e3\u4e00\u4e0b\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u5982\u4f55\u5f15\u7528wxml\u6587\u4ef6\u3001\u89c6\u56fe\u6a21\u7248\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u75282\u79cd\u65b9\u5f0f\u6765\u5f15\u7528wxml\u6587\u4ef6\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5305\u542b\u91cd\u590d\u7684\u5185\u5bb9\uff0c\u8ba9\u7f51\u9875\u5185\u5bb9\u548c\u903b\u8f91\u7ed3\u6784\u66f4\u52a0\u7b80\u5355\u660e\u4e5f\u66f4\u52a0\u8f7b\u91cf\u7ea7\u3002\u6b64\u5916\uff0c\u5728\u7b2c\u4e8c\u79cd\u65b9\u6cd5\u4e2d\uff0c\u5927\u5bb6\u53ef\u4ee5\u4e86\u89e3\u5230\uff0c\u7528\u6a21\u677f\u7684\u65b9\u5f0f\u53bb\u5f15\u7528wxml\u6587\u4ef6\u3002\u6700\u540e\u518d\u7a0b\u5e8f\u9000\u51fa\u65f6\uff0c\u5982\u4f55\u6e05\u7406\u7684\u65b9\u5f0f\uff0c\u901a\u8fc7\u5c0f\u7a0b\u5e8f\u7684\u751f\u547d\u5468\u671f\u7684\u4ecb\u7ecd\uff0c\u5927\u5bb6\u53ef\u4ee5\u6e05\u695a\u7684\u77e5\u9053\u5c0f\u7a0b\u5e8f\u5728\u5404\u4e2a\u9636\u6bb5\u7684\u4e8b\u4ef6\uff0c\u4ee5\u540e\u9700\u8981\u5728\u4e0d\u540c\u7684\u9636\u6bb5\u5b89\u6392\u6267\u884c\u4e0d\u540c\u7684\u4efb\u52a1\uff0c\u53ef\u4ee5\u5199\u5728\u5bf9\u5e94\u7684\u4e8b\u4ef6\u4e2d\u3002 \u6838\u5fc3\u5185\u5bb9 wxml\u6587\u4ef6\u76842\u79cd\u5f15\u7528\uff08include\u3001import\uff09 \u6a21\u7248\u7684\u4f7f\u7528 \u5c0f\u7a0b\u5e8f\u751f\u547d\u5468\u671f \u5b9e\u4f8b\u4e00: include\u65b9\u5f0f\u5f15\u7528header.wxml\u6587\u4ef6 \u6587\u4ef6\u5f15\u7528\u5bf9\u4e8e\u4ee3\u7801\u7684\u91cd\u7528\u975e\u5e38\u91cd\u8981\uff0c\u4f8b\u5982\u5728web\u5f00\u53d1\u4e2d\u6211\u4eec\u53ef\u4ee5\u5c06\u516c\u7528\u7684header\u90e8\u5206\u548cfooter\u7b49\u90e8\u5206\u8fdb\u884c\u63d0\u53d6\uff0c\u7136\u540e\u5728\u9700\u8981\u7684\u5730\u65b9\u8fdb\u884c\u5f15\u7528\u3002\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u91cc\u9762\uff0c\u662f\u5305\u542b\u5f15\u7528\u529f\u80fd\u7684\u2014\u2014include\u3001import\u3002\u8fd9\u4e24\u4e2a\u5f15\u7528\u6587\u4ef6\u7684\u6807\u7b7e\uff0c\u4f7f\u7528\u57fa\u672c\u5dee\u4e0d\u591a\uff0c\u8fd9\u91cc\u5148\u8bf4\u4e00\u4e0binclude\u3002\u5fae\u4fe1\u4e2d\u7684\u89c6\u56fe\u6587\u4ef6\u5f15\u7528\uff0c\u5f15\u7528\u8fc7\u6765\u7684\u90fd\u662f\u6ca1\u6709\u6e32\u67d3\u7684\uff0c\u57fa\u672c\u7c7b\u4f3c\u4e8e\u76f4\u63a5\u5c06\u5f15\u7528\u8fc7\u6765\u7684\u6587\u4ef6\u590d\u5236\u5230\u5f15\u7528\u4f4d\u7f6e\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u91cd\u65b0\u5bf9\u5176\u6e32\u67d3\u3002\u5b9e\u4f8b\u8bf4\u660e \u8fd9\u91cc\u5c06\u9ed8\u8ba4\u521b\u5efa\u7684\u7528\u6237\u5934\u50cf\u4fe1\u606f\u63d0\u53d6\u51fa\u5230header.wxml\u4e2d\uff0c\u505a\u4e3a\u5934\u90e8\u5f15\u7528\uff0c\u5206\u522b\u7531index2.wxml\u548cindex3.wxml\u5f15\u7528\uff0c\u5f15\u7528\u65b9\u5f0f\u4e3ainclude\u3002\u5b9e\u4f8b\u4ee3\u7801 \u5728pages\u4e2d\u521b\u5efacommon\/header.wxml\u4eceindex.wxml\u4e2d\u5c06\u7cfb\u7edf\u9ed8\u8ba4\u521b\u5efa\u7684\u7528\u6237\u4fe1\u606f\u7ed3\u6784\u590d\u5236\u5230header.wxml\u4e2d\u3002header.wxml\u4ee3\u7801\uff1a &lt;!&#8211;pages\/common\/header.wxml&#8211;&gt; &nbsp;&nbsp;&lt;view&gt; &nbsp;&nbsp;&nbsp;&nbsp;&lt;image&gt;&lt;\/image&gt; &nbsp;&nbsp;&nbsp;&nbsp;&lt;text&gt;{{userInfo.nickName}}&lt;\/text&gt; &nbsp;&nbsp;&lt;\/view&gt; \u767b\u5f55\u540e\u590d\u5236 \u56e0\u4e3a\u4e24\u4e2a\u9875\u9762\u90fd\u8981\u5305\u542bheader.wxml\uff0c\u6240\u4ee5\u6837\u5f0f\u6587\u4ef6\u5c31\u4e0d\u91cd\u590d\u5199\u4e86\uff0c\u8fd9\u91cc\u76f4\u63a5\u5c06\u6837\u5f0f\u62f7\u8d1d\u5230app.wxss\u3002app.wxss\u4ee3\u7801\uff1a \/**app.wxss**\/ .userinfo&nbsp;{ &nbsp;&nbsp;display:&nbsp;flex; &nbsp;&nbsp;flex-direction:&nbsp;column; &nbsp;&nbsp;align-items:&nbsp;center; } &nbsp; .userinfo-avatar&nbsp;{ &nbsp;&nbsp;width:&nbsp;128rpx; &nbsp;&nbsp;height:&nbsp;128rpx; &nbsp;&nbsp;margin:&nbsp;20rpx; &nbsp;&nbsp;border-radius:&nbsp;50%; } &nbsp; .userinfo-nickname&nbsp;{ &nbsp;&nbsp;color:&nbsp;#aaa; } \u767b\u5f55\u540e\u590d\u5236 \u521b\u5efaindex\/index2\u548cindex\/index3 index2.wxml\u5185\u5bb9\uff1a &lt;!&#8211;pages\/index\/index2.wxml&#8211;&gt; &lt;view&gt; &nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;&lt;\/include&gt; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&lt;view&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;button&gt;\u8fdb\u5165index3&lt;\/button&gt; &nbsp;&nbsp;&nbsp;&nbsp;&lt;\/view&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/view&gt; \u767b\u5f55\u540e\u590d\u5236 \u56e0\u4e3aindex2.wxml\u548cindex3.wxml\u90fd\u9700\u8981userInfo\u6570\u636e\uff0c\u6240\u4ee5\u8fd9\u8fb9\u5728index2\u83b7\u53d6\u5230\u6570\u636e\u540e\uff0c\u4f7f\u7528\u672c\u5730\u5b58\u50a8\u8fdb\u884c\u5b58\u50a8\uff0cindex3.wxml\u8bfb\u53d6\u672c\u5730\u5b58\u50a8\u3002 index2.js\u4ee3\u7801\uff1a \/\/&nbsp;pages\/index\/index2.js var&nbsp;app&nbsp;=&nbsp;getApp() &nbsp; Page({ &nbsp;&nbsp;data:&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;userInfo:&nbsp;{}, &nbsp;&nbsp;}, [&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-28783","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28783","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=28783"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28783\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}