{"id":29808,"date":"2024-11-25T10:04:34","date_gmt":"2024-11-25T02:04:34","guid":{"rendered":"https:\/\/fwq.ai\/blog\/29808\/"},"modified":"2024-11-25T10:04:34","modified_gmt":"2024-11-25T02:04:34","slug":"%e5%b0%8f%e7%a8%8b%e5%ba%8f%e5%bc%80%e5%8f%91%e5%9f%ba%e7%a1%80%e7%af%87%e4%b9%8b%e6%95%b0%e6%8d%ae%e7%bb%91%e5%ae%9a%e4%b8%8a%e7%af%87%ef%bc%887%ef%bc%89","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/29808\/","title":{"rendered":"\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u57fa\u7840\u7bc7\u4e4b\u6570\u636e\u7ed1\u5b9a\u4e0a\u7bc7\uff087\uff09"},"content":{"rendered":"<p>\u5728\u4e4b\u524d\u7684\u6559\u7a0b\u4e2d\u5199\u5230\uff0c\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u6846\u67b6\u5c06\u7a0b\u5e8f\u5206\u4e3a\u903b\u8f91\u5c42(.js\u6587\u4ef6)\u548c\u89c6\u56fe\u5c42(.wxml\u6587\u4ef6)\u3002\u8fd9\u662f\u4e00\u79cd\u5e38\u89c1\u7684ui\u548c\u903b\u8f91\u5206\u79bb\u7684\u7a0b\u5e8f\u8bbe\u8ba1\u65b9\u5f0f\uff0c\u5f00\u53d1\u51fa\u6765\u7684\u7a0b\u5e8f\u66f4\u52a0\u7075\u6d3b\uff0c\u6613\u6269\u5c55\u3002<\/p>\n<p>\u8fd9\u79cd\u7a0b\u5e8f\u8bbe\u8ba1\u65b9\u5f0f\u901a\u5e38\u8981\u89e3\u51b3\u4e24\u4e2a\u95ee\u9898:<\/p>\n<blockquote><p>\n  UI\u5c42\u54cd\u5e94\u903b\u8f91\u5c42\u903b\u8f91\u548c\u6570\u636e\u7684\u53d8\u5316UI\u5c42\u5c06\u7528\u6237\u7684\u64cd\u4f5c\u53cd\u9988\u5230\u903b\u8f91\u5c42\n<\/p><\/blockquote>\n<p>\u901a\u5e38\u6765\u8bf4\u53ef\u4ee5\u8ba9UI\u5c42\u548c\u903b\u8f91\u5c42\u4e92\u76f8\u66b4\u9732\u63a5\u53e3\u7ed9\u5bf9\u65b9\uff0c\u4e0d\u8fc7\u51fa\u4e8e\u5bf9\u7075\u6d3b\u6027\u548c\u6269\u5c55\u6027\u7684\u8003\u8651\uff0c\u4f1a\u5f15\u5165\u4e2d\u95f4\u5c42\u6765\u8fdb\u884c\u7ba1\u7406\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514dUI\u5c42\u548c\u903b\u8f91\u5c42\u4e4b\u95f4\u7684\u76f4\u63a5\u4f9d\u8d56\u3002<\/p>\n<p>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u6846\u67b6\u6b63\u662f\u57fa\u4e8e\u8fd9\u79cd\u6a21\u5f0f\u8fdb\u884c\u8bbe\u8ba1\u7684\uff0c.wxml\u6587\u4ef6\u6765\u63cf\u8ff0UI\u5c42(\u5fae\u4fe1\u5b98\u65b9\u540d\u79f0\u4e3a<strong>\u89c6\u56fe\u5c42<\/strong>\uff0c\u6559\u7a0b\u540e\u7eed\u4e5f\u5c06\u7528<strong>\u89c6\u56fe\u5c42<\/strong>\u6765\u547d\u540d)\uff0c.js\u6587\u4ef6\u6765\u5904\u7406\u903b\u8f91\u5c42\uff0c\u800c\u5fae\u4fe1\u7684\u6846\u67b6\u5219\u4f5c\u4e3a\u4e2d\u95f4\u5c42\u7ba1\u7406\u4e24\u8005\u4e4b\u95f4\u7684\u8c03\u7528\u3002<\/p>\n<p>\u4e3a\u4e86\u66f4\u597d\u7684\u5e2e\u52a9\u5f00\u53d1\u8005\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0c\u5fae\u4fe1\u5b9a\u4e49\u4e86\u4e00\u4e9b\u8bed\u6cd5\u548c\u89c4\u5219\u6765\u5e2e\u52a9\u5f00\u53d1\u8005\u8fde\u63a5\u89c6\u56fe\u5c42\u548c\u903b\u8f91\u5c42\u3002<\/p>\n<h2><strong>\u6570\u636e\u7ed1\u5b9a<\/strong><\/h2>\n<p><strong>\u663e\u793a\u5b57\u7b26\u4e32\u5185\u5bb9<\/strong><\/p>\n<pre>\/\/page.wxml\r\n&lt;text&gt;{{motto}}&lt;\/text&gt;\r\n\r\n\/\/page.js\r\n&nbsp;data:&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;motto:&nbsp;'Hello&nbsp;World',\r\n&nbsp;&nbsp;},<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u901a\u8fc7\u5c06&#8221;{{motto}}&#8221;\u5d4c\u5165\u89c6\u56fe\u5c42\u4ee3\u7801\u4e2d\uff0c\u754c\u9762\u4f1a\u663e\u793a&#8221;Hello World&#8221;<\/p>\n<p><strong>\u66f4\u6539\u5b57\u7b26\u4e32\u5185\u5bb9<\/strong><\/p>\n<pre>setData({\r\n&nbsp;&nbsp;motto:'Hello&nbsp;My&nbsp;World'\r\n&nbsp;&nbsp;})<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5f53\u6267\u884c\u4e0a\u8ff0\u4ee3\u7801\u540e\uff0c\u754c\u9762\u4f1a\u663e\u793a&#8221;Hello My World&#8221;<\/p>\n<p>\u4e0a\u8ff0\u90e8\u5206\u6709\u4e24\u70b9\u9700\u8981\u8bf4\u660e:<\/p>\n<p>1: \u89c6\u56fe\u5c42\u5d4c\u5165\u7684\u662f{{motto}}\u800c\u4e0d\u662f{{data.motto}}\uff0c\u5fae\u4fe1\u6846\u67b6\u9ed8\u8ba4\u8bbe\u5b9a\u89c6\u56fe\u5c42\u7ed1\u5b9a\u7684\u53d8\u91cf\u5b9a\u4e49\u5728Page\u5bf9\u8c61\u7684<strong>data\u5c5e\u6027<\/strong>\u4e2d\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u53d8\u91cf\u9700\u8981\u7ed1\u5b9a\u5230\u89c6\u56fe\u5c42\uff0c\u4e00\u5b9a\u8981\u5b9a\u4e49<strong>data\u5c5e\u6027<\/strong>\u4e2d<\/p>\n<p>2: \u901a\u8fc7\u8c03\u7528Page\u5bf9\u8c61\u7684setData(Page\u5bf9\u8c61\u9884\u5b9a\u4e49)\u65b9\u6cd5\uff0c\u53ef\u4ee5\u66f4\u65b0\u754c\u9762\u6570\u636e\uff0c\u4f46\u662f<strong>\u76f4\u63a5\u8bbe\u7f6e\u53d8\u91cf\u662f\u65e0\u6548\u7684<\/strong>\uff0c\u56e0\u6b64\u5bf9\u4e8e\u7ed1\u5b9a\u5230\u89c6\u56fe\u5c42\u7684\u53d8\u91cf\uff0c\u8981\u6c38\u8fdc\u4f7f\u7528setData\u65b9\u6cd5\u6765\u8bbe\u7f6e\u53d8\u91cf\u503c<\/p>\n<p><strong>\u663e\u793a\u56fe\u7247<\/strong><br \/>\u5728\u5f00\u53d1\u5de5\u5177\u9ed8\u8ba4\u751f\u6210\u7684\u7a0b\u5e8f\u9996\u9875\uff0c\u663e\u793a\u4e86\u7528\u6237\u7684\u5934\u50cf\uff0c\u76f8\u5173\u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre>\/\/index.wxml\r\n&nbsp;&lt;image&gt;&lt;\/image&gt;\r\n\r\n\/\/index.js\r\nonLoad:&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;\/\/\u8c03\u7528\u5e94\u7528\u5b9e\u4f8b\u7684\u65b9\u6cd5\u83b7\u53d6\u5168\u5c40\u6570\u636e\r\n&nbsp;&nbsp;&nbsp;&nbsp;app.getUserInfo(function(userInfo){\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u66f4\u65b0\u6570\u636e\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;that.setData({\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userInfo:userInfo\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;})\r\n&nbsp;&nbsp;&nbsp;&nbsp;})\r\n&nbsp;&nbsp;}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>image\u6807\u7b7e\u7684src\u5c5e\u6027\u7ed1\u5b9a\u4e86userInfo.avatarUrl\u53d8\u91cf\uff0c\u5e76\u5728onLoad\u65b9\u6cd5\u4e2d\u901a\u8fc7\u8c03\u7528setData\u65b9\u6cd5\u8bbe\u7f6euserInfo\u3002<\/p>\n<p><strong>\u5c5e\u6027\u7ed1\u5b9a<\/strong><\/p>\n<p>\u53ef\u4ee5\u5c06\u53d8\u91cf\u7ed1\u5b9a\u5230\u89c6\u56fe\u7ec4\u4ef6\u7684\u5c5e\u6027\u503c\u4e0a(\u5982\u4e0a\u9762image\u6807\u7b7e\u7684src\u5c5e\u6027)\uff0c<strong>\u6ce8\u610f\u5728\u7ed1\u5b9a\u5230\u5c5e\u6027\u65f6\uff0c\u9700\u8981\u5728\u5916\u9762\u52a0\u5165\u4e00\u5bf9\u53cc\u5f15\u53f7\u3002<\/strong><\/p>\n<pre>src=\"{{userInfo.avatarUrl}}\"<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u9664\u4e86\u7528\u4e8e\u663e\u793a\u56fe\u7247\u5916\uff0c\u5c5e\u6027\u7ed1\u5b9a\u8fd8\u6709\u8bb8\u591a\u4f5c\u7528\u3002<\/p>\n<blockquote>\n<p>\u5173\u8054\u6570\u636e<\/p>\n<\/blockquote>\n<p>\u5047\u8bbe\u8981\u505a\u4e00\u4e2a\u5b66\u751f\u7ba1\u7406\u7a0b\u5e8f\uff0c\u9875\u9762\u4f7f\u7528\u5217\u8868\u6765\u5c55\u793a\u7528\u6237\u6570\u636e\uff0c\u5f53\u7528\u6237\u70b9\u51fb\u67d0\u4e00\u5b66\u751f\u4fe1\u606f\u65f6\uff0c\u8fdb\u5165\u8be5\u5b66\u751f\u7684\u8be6\u60c5\u9875\u9875\u9762\u3002<br \/>\u5f53\u83b7\u53d6\u5230\u7528\u6237\u7684\u70b9\u51fb\u4e8b\u4ef6\u65f6\uff0c\u5fc5\u987b\u8981\u77e5\u9053\u70b9\u51fb\u7684\u662f\u54ea\u4e00\u4e2a\u5b66\u751f\u7684\u6570\u636e\uff0c\u8fd9\u65f6\u53ef\u4ee5\u5c06\u5b66\u751f\u7684id\u7ed1\u5b9a\u5230\u89c6\u56fe\u7ec4\u4ef6\u7684id\u5c5e\u6027\u4e2d\u6765\u8fdb\u884c\u6570\u636e\u5173\u8054\u3002<\/p>\n<blockquote>\n<p>\u63a7\u5236\u89c6\u56fe\u7684\u9690\u85cf\/\u663e\u793a<\/p>\n<\/blockquote>\n<p>\u53ef\u4ee5\u5c06\u53d8\u91cf\u7ed1\u5b9a\u5230\u89c6\u56fe\u7ec4\u4ef6\u7684hidden\u5c5e\u6027\u4e2d\uff0c\u901a\u8fc7\u66f4\u6539\u7ec4\u4ef6hidden\u5c5e\u6027\u7684\u503c\uff0c\u53ef\u4ee5\u63a7\u5236\u7ec4\u4ef6\u662f\u5426\u663e\u793a\u3002<\/p>\n<p><strong>\u63a7\u5236\u5c5e\u6027<\/strong><br \/>\u4e0a\u9762\u8bf4\u5230\u53ef\u4ee5\u901a\u8fc7\u5c5e\u6027\u7ed1\u5b9a\u7684\u65b9\u6cd5\u6765\u63a7\u5236\u89c6\u56fe\u7ec4\u4ef6\u662f\u5426\u663e\u793a\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u63a7\u5236\u5c5e\u6027\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u3002<\/p>\n<pre>\/\/Page.wxml\r\n&lt;view&gt;&nbsp;&lt;\/view&gt;\r\n\r\n\/\/Page.js\r\nPage({\r\n&nbsp;&nbsp;data:&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;condition:&nbsp;true\r\n&nbsp;&nbsp;}\r\n})<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u901a\u8fc7\u7ed1\u5b9a\u6570\u636e\u5230wx:if\u5c5e\u6027\uff0c\u53ef\u4ee5\u63a7\u5236\u8be5\u7ec4\u4ef6\u662f\u5426\u663e\u793a\u3002<br \/>\u6846\u67b6\u8fd8\u63d0\u4f9b\u4e86wx:elif\u548cwx:else\u5c5e\u6027\uff0c\u7528\u6cd5\u5982\u4e0b:<\/p>\n<pre>&lt;view&gt;&nbsp;5}}\"&amp;gt;&nbsp;1&nbsp;&lt;\/view&gt;&lt;view&gt;&nbsp;2}}\"&amp;gt;&nbsp;2&nbsp;&lt;\/view&gt;&lt;view&gt;&nbsp;3&nbsp;&lt;\/view&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5982\u679c\u60f3\u540c\u65f6\u63a7\u5236\u591a\u4e2a\u89c6\u56fe\u7ec4\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528block wx:if<\/p>\n<pre>&lt;block&gt;\r\n&nbsp;&nbsp;&lt;view&gt;&nbsp;view1&nbsp;&lt;\/view&gt;\r\n&nbsp;&nbsp;&lt;view&gt;&nbsp;view2&nbsp;&lt;\/view&gt;&lt;\/block&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u540c\u6837\uff0c\u63a7\u5236\u5c5e\u6027\u7ed1\u5b9a\u65f6\u4e5f\u9700\u8981\u6dfb\u52a0\u53cc\u5f15\u53f7<\/strong><\/p>\n<p><strong>wx:if vs hidden<\/strong><\/p>\n<blockquote>\n<p>\u4e00\u822c\u6765\u8bf4\uff0cwx:if \u6709\u66f4\u9ad8\u7684\u5207\u6362\u6d88\u8017\u800c hidden \u6709\u66f4\u9ad8\u7684\u521d\u59cb\u6e32\u67d3\u6d88\u8017\u3002\u56e0\u6b64\uff0c\u5982\u679c\u9700\u8981\u9891\u7e41\u5207\u6362\u7684\u60c5\u666f\u4e0b\uff0c\u7528 hidden<br \/>\u66f4\u597d\uff0c\u5982\u679c\u5728\u8fd0\u884c\u65f6\u6761\u4ef6\u4e0d\u5927\u53ef\u80fd\u6539\u53d8\u5219 wx:if \u8f83\u597d\u3002<\/p>\n<\/blockquote>\n<p><strong>\u5173\u952e\u5b57<\/strong><br \/>\u6846\u67b6\u63d0\u4f9b\u4e86\u4e24\u4e2a\u5173\u952e\u5b57\u6765\u8868\u793a<strong>\u771f<\/strong>\u548c<strong>\u5047<\/strong><br \/>true\uff1aboolean \u7c7b\u578b\u7684 true\uff0c\u4ee3\u8868\u771f\u503c\u3002<br \/>false\uff1a boolean \u7c7b\u578b\u7684 false\uff0c\u4ee3\u8868\u5047\u503c\u3002<\/p>\n<p>\u4ee3\u7801\u793a\u4f8b<\/p>\n<pre>&lt;checkbox&gt;&nbsp;&lt;\/checkbox&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<blockquote>\n<p>\u7279\u522b\u6ce8\u610f\uff1a\u4e0d\u8981\u76f4\u63a5\u5199 checked=&#8221;false&#8221;\uff0c\u5176\u8ba1\u7b97\u7ed3\u679c\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8f6c\u6210 boolean \u7c7b\u578b\u540e\u4ee3\u8868\u771f\u503c\u3002<\/p>\n<\/blockquote>\n<p>\u5173\u4e8e\u6570\u636e\u7ed1\u5b9a\u7684\u66f4\u591a\u8bb2\u8ff0\uff0c\u656c\u8bf7\u671f\u5f85<strong>\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u57fa\u7840\u7bc7\u4e4b\u6570\u636e\u7ed1\u5b9a\u4e0b\uff088\uff09<\/strong><\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u57fa\u7840\u7bc7\u4e4b\u6570\u636e\u7ed1\u5b9a\u4e0a\u7bc7\uff087\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>\u5728\u4e4b\u524d\u7684\u6559\u7a0b\u4e2d\u5199\u5230\uff0c\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u6846\u67b6\u5c06\u7a0b\u5e8f\u5206\u4e3a\u903b\u8f91\u5c42(.js\u6587\u4ef6)\u548c\u89c6\u56fe\u5c42(.wxml\u6587\u4ef6)\u3002\u8fd9\u662f\u4e00\u79cd\u5e38\u89c1\u7684ui\u548c\u903b\u8f91\u5206\u79bb\u7684\u7a0b\u5e8f\u8bbe\u8ba1\u65b9\u5f0f\uff0c\u5f00\u53d1\u51fa\u6765\u7684\u7a0b\u5e8f\u66f4\u52a0\u7075\u6d3b\uff0c\u6613\u6269\u5c55\u3002 \u8fd9\u79cd\u7a0b\u5e8f\u8bbe\u8ba1\u65b9\u5f0f\u901a\u5e38\u8981\u89e3\u51b3\u4e24\u4e2a\u95ee\u9898: UI\u5c42\u54cd\u5e94\u903b\u8f91\u5c42\u903b\u8f91\u548c\u6570\u636e\u7684\u53d8\u5316UI\u5c42\u5c06\u7528\u6237\u7684\u64cd\u4f5c\u53cd\u9988\u5230\u903b\u8f91\u5c42 \u901a\u5e38\u6765\u8bf4\u53ef\u4ee5\u8ba9UI\u5c42\u548c\u903b\u8f91\u5c42\u4e92\u76f8\u66b4\u9732\u63a5\u53e3\u7ed9\u5bf9\u65b9\uff0c\u4e0d\u8fc7\u51fa\u4e8e\u5bf9\u7075\u6d3b\u6027\u548c\u6269\u5c55\u6027\u7684\u8003\u8651\uff0c\u4f1a\u5f15\u5165\u4e2d\u95f4\u5c42\u6765\u8fdb\u884c\u7ba1\u7406\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514dUI\u5c42\u548c\u903b\u8f91\u5c42\u4e4b\u95f4\u7684\u76f4\u63a5\u4f9d\u8d56\u3002 \u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u6846\u67b6\u6b63\u662f\u57fa\u4e8e\u8fd9\u79cd\u6a21\u5f0f\u8fdb\u884c\u8bbe\u8ba1\u7684\uff0c.wxml\u6587\u4ef6\u6765\u63cf\u8ff0UI\u5c42(\u5fae\u4fe1\u5b98\u65b9\u540d\u79f0\u4e3a\u89c6\u56fe\u5c42\uff0c\u6559\u7a0b\u540e\u7eed\u4e5f\u5c06\u7528\u89c6\u56fe\u5c42\u6765\u547d\u540d)\uff0c.js\u6587\u4ef6\u6765\u5904\u7406\u903b\u8f91\u5c42\uff0c\u800c\u5fae\u4fe1\u7684\u6846\u67b6\u5219\u4f5c\u4e3a\u4e2d\u95f4\u5c42\u7ba1\u7406\u4e24\u8005\u4e4b\u95f4\u7684\u8c03\u7528\u3002 \u4e3a\u4e86\u66f4\u597d\u7684\u5e2e\u52a9\u5f00\u53d1\u8005\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0c\u5fae\u4fe1\u5b9a\u4e49\u4e86\u4e00\u4e9b\u8bed\u6cd5\u548c\u89c4\u5219\u6765\u5e2e\u52a9\u5f00\u53d1\u8005\u8fde\u63a5\u89c6\u56fe\u5c42\u548c\u903b\u8f91\u5c42\u3002 \u6570\u636e\u7ed1\u5b9a \u663e\u793a\u5b57\u7b26\u4e32\u5185\u5bb9 \/\/page.wxml &lt;text&gt;{{motto}}&lt;\/text&gt; \/\/page.js &nbsp;data:&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;motto:&nbsp;&#8216;Hello&nbsp;World&#8217;, &nbsp;&nbsp;}, \u767b\u5f55\u540e\u590d\u5236 \u901a\u8fc7\u5c06&#8221;{{motto}}&#8221;\u5d4c\u5165\u89c6\u56fe\u5c42\u4ee3\u7801\u4e2d\uff0c\u754c\u9762\u4f1a\u663e\u793a&#8221;Hello World&#8221; \u66f4\u6539\u5b57\u7b26\u4e32\u5185\u5bb9 setData({ &nbsp;&nbsp;motto:&#8217;Hello&nbsp;My&nbsp;World&#8217; &nbsp;&nbsp;}) \u767b\u5f55\u540e\u590d\u5236 \u5f53\u6267\u884c\u4e0a\u8ff0\u4ee3\u7801\u540e\uff0c\u754c\u9762\u4f1a\u663e\u793a&#8221;Hello My World&#8221; \u4e0a\u8ff0\u90e8\u5206\u6709\u4e24\u70b9\u9700\u8981\u8bf4\u660e: 1: \u89c6\u56fe\u5c42\u5d4c\u5165\u7684\u662f{{motto}}\u800c\u4e0d\u662f{{data.motto}}\uff0c\u5fae\u4fe1\u6846\u67b6\u9ed8\u8ba4\u8bbe\u5b9a\u89c6\u56fe\u5c42\u7ed1\u5b9a\u7684\u53d8\u91cf\u5b9a\u4e49\u5728Page\u5bf9\u8c61\u7684data\u5c5e\u6027\u4e2d\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u53d8\u91cf\u9700\u8981\u7ed1\u5b9a\u5230\u89c6\u56fe\u5c42\uff0c\u4e00\u5b9a\u8981\u5b9a\u4e49data\u5c5e\u6027\u4e2d 2: \u901a\u8fc7\u8c03\u7528Page\u5bf9\u8c61\u7684setData(Page\u5bf9\u8c61\u9884\u5b9a\u4e49)\u65b9\u6cd5\uff0c\u53ef\u4ee5\u66f4\u65b0\u754c\u9762\u6570\u636e\uff0c\u4f46\u662f\u76f4\u63a5\u8bbe\u7f6e\u53d8\u91cf\u662f\u65e0\u6548\u7684\uff0c\u56e0\u6b64\u5bf9\u4e8e\u7ed1\u5b9a\u5230\u89c6\u56fe\u5c42\u7684\u53d8\u91cf\uff0c\u8981\u6c38\u8fdc\u4f7f\u7528setData\u65b9\u6cd5\u6765\u8bbe\u7f6e\u53d8\u91cf\u503c \u663e\u793a\u56fe\u7247\u5728\u5f00\u53d1\u5de5\u5177\u9ed8\u8ba4\u751f\u6210\u7684\u7a0b\u5e8f\u9996\u9875\uff0c\u663e\u793a\u4e86\u7528\u6237\u7684\u5934\u50cf\uff0c\u76f8\u5173\u4ee3\u7801\u5982\u4e0b: \/\/index.wxml &nbsp;&lt;image&gt;&lt;\/image&gt; \/\/index.js onLoad:&nbsp;function&nbsp;()&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;console.log(&#8216;onLoad&#8217;) &nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;that&nbsp;=&nbsp;this &nbsp;&nbsp;&nbsp;&nbsp;\/\/\u8c03\u7528\u5e94\u7528\u5b9e\u4f8b\u7684\u65b9\u6cd5\u83b7\u53d6\u5168\u5c40\u6570\u636e &nbsp;&nbsp;&nbsp;&nbsp;app.getUserInfo(function(userInfo){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u66f4\u65b0\u6570\u636e &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;that.setData({ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;userInfo:userInfo &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}) &nbsp;&nbsp;&nbsp;&nbsp;}) &nbsp;&nbsp;} \u767b\u5f55\u540e\u590d\u5236 image\u6807\u7b7e\u7684src\u5c5e\u6027\u7ed1\u5b9a\u4e86userInfo.avatarUrl\u53d8\u91cf\uff0c\u5e76\u5728onLoad\u65b9\u6cd5\u4e2d\u901a\u8fc7\u8c03\u7528setData\u65b9\u6cd5\u8bbe\u7f6euserInfo\u3002 \u5c5e\u6027\u7ed1\u5b9a \u53ef\u4ee5\u5c06\u53d8\u91cf\u7ed1\u5b9a\u5230\u89c6\u56fe\u7ec4\u4ef6\u7684\u5c5e\u6027\u503c\u4e0a(\u5982\u4e0a\u9762image\u6807\u7b7e\u7684src\u5c5e\u6027)\uff0c\u6ce8\u610f\u5728\u7ed1\u5b9a\u5230\u5c5e\u6027\u65f6\uff0c\u9700\u8981\u5728\u5916\u9762\u52a0\u5165\u4e00\u5bf9\u53cc\u5f15\u53f7\u3002 src=&#8221;{{userInfo.avatarUrl}}&#8221; \u767b\u5f55\u540e\u590d\u5236 \u9664\u4e86\u7528\u4e8e\u663e\u793a\u56fe\u7247\u5916\uff0c\u5c5e\u6027\u7ed1\u5b9a\u8fd8\u6709\u8bb8\u591a\u4f5c\u7528\u3002 \u5173\u8054\u6570\u636e \u5047\u8bbe\u8981\u505a\u4e00\u4e2a\u5b66\u751f\u7ba1\u7406\u7a0b\u5e8f\uff0c\u9875\u9762\u4f7f\u7528\u5217\u8868\u6765\u5c55\u793a\u7528\u6237\u6570\u636e\uff0c\u5f53\u7528\u6237\u70b9\u51fb\u67d0\u4e00\u5b66\u751f\u4fe1\u606f\u65f6\uff0c\u8fdb\u5165\u8be5\u5b66\u751f\u7684\u8be6\u60c5\u9875\u9875\u9762\u3002\u5f53\u83b7\u53d6\u5230\u7528\u6237\u7684\u70b9\u51fb\u4e8b\u4ef6\u65f6\uff0c\u5fc5\u987b\u8981\u77e5\u9053\u70b9\u51fb\u7684\u662f\u54ea\u4e00\u4e2a\u5b66\u751f\u7684\u6570\u636e\uff0c\u8fd9\u65f6\u53ef\u4ee5\u5c06\u5b66\u751f\u7684id\u7ed1\u5b9a\u5230\u89c6\u56fe\u7ec4\u4ef6\u7684id\u5c5e\u6027\u4e2d\u6765\u8fdb\u884c\u6570\u636e\u5173\u8054\u3002 \u63a7\u5236\u89c6\u56fe\u7684\u9690\u85cf\/\u663e\u793a [&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-29808","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29808","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=29808"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29808\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=29808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=29808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=29808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}