{"id":34294,"date":"2024-11-25T15:40:33","date_gmt":"2024-11-25T07:40:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/34294\/"},"modified":"2024-11-25T15:40:33","modified_gmt":"2024-11-25T07:40:33","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e5%9f%ba%e7%a1%80%e5%8a%a0%e5%bc%ba%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/34294\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u57fa\u7840\u52a0\u5f3a\u603b\u7ed3"},"content":{"rendered":"<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86\u5173\u4e8e\u7684\u76f8\u5173\u95ee\u9898\uff0c\u5176\u4e2d\u4e3b\u8981\u4ecb\u7ecd\u4e86\u4e00\u4e9b\u57fa\u7840\u5185\u5bb9\uff0c\u5305\u62ec\u4e86\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u3001\u6837\u5f0f\u9694\u79bb\u3001\u6570\u636e\u3001\u65b9\u6cd5\u548c\u5c5e\u6027\u7b49\u7b49\u5185\u5bb9\uff0c\u4e0b\u9762\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u6709\u5e2e\u52a9\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/067\/6347a59144b68204.jpg\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u57fa\u7840\u52a0\u5f3a\u603b\u7ed3\u63d2\u56fe\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u57fa\u7840\u52a0\u5f3a\u603b\u7ed3\u63d2\u56fe\" \/><\/p>\n<p>\u3010\u76f8\u5173\u5b66\u4e60\u63a8\u8350\uff1a\u3011<\/p>\n<h2>1\u3001\u81ea\u5b9a\u4e49\u7ec4\u4ef6<\/h2>\n<p><span style=\"font-size: 18px\"><strong>1.1\u3001\u521b\u5efa\u7ec4\u4ef6<\/strong><\/span><\/p>\n<ul>\n<li>\n<p>\u5728\u9879\u76ee\u7684\u6839\u76ee\u5f55\u4e2d\uff0c\u9f20\u6807\u53f3\u952e\uff0c\u521b\u5efa components -&gt; test \u6587\u4ef6\u5939<\/p>\n<\/li>\n<li>\n<p>\u65b0\u5efa\u7684 components -&gt; test \u6587\u4ef6\u5939\u4e0a\uff0c\u9f20\u6807\u53f3\u952e\uff0c\u70b9\u51fb\u65b0\u5efa Component<\/p>\n<\/li>\n<li>\n<p>\u952e\u5165\u7ec4\u4ef6\u7684\u540d\u79f0\u4e4b\u540e\u56de\u8f66\uff0c\u4f1a\u81ea\u52a8\u751f\u6210\u7ec4\u4ef6\u5bf9\u5e94\u7684 4 \u4e2a\u6587\u4ef6\uff0c\u540e\u7f00\u540d\u5206\u522b\u4e3a .js\u3001.json\u3001.wxml \u548c .wxss<\/p>\n<\/li>\n<\/ul>\n<p><span style=\"font-size: 18px\"><strong>1.2\u3001\u5f15\u7528\u7ec4\u4ef6<\/strong><\/span><\/p>\n<ul>\n<li>\n<p>\u5c40\u90e8\u5f15\u7528\uff1a\u7ec4\u4ef6\u53ea\u80fd\u5728\u5f53\u524d\u88ab\u5f15\u7528\u7684\u9875\u9762\u5185\u4f7f\u7528<\/p>\n<\/li>\n<li>\n<p>\u5168\u5c40\u5f15\u7528\uff1a\u7ec4\u4ef6\u53ef\u4ee5\u5728\u6bcf\u4e2a\u5c0f\u7a0b\u5e8f\u9875\u9762\u4e2d\u4f7f\u7528<\/p>\n<\/li>\n<\/ul>\n<p><span style=\"font-size: 18px\"><strong>1.3\u3001\u5c40\u90e8\u5f15\u7528\u7ec4\u4ef6<\/strong><\/span><\/p>\n<p>\u5728\u9875\u9762\u7684 .json \u914d\u7f6e\u6587\u4ef6\u4e2d\u5f15\u7528\u7ec4\u4ef6\u7684\u65b9\u5f0f\uff0c\u53eb\u505a\u5c40\u90e8\u5f15\u7528\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>#&nbsp;\u5728\u9875\u9762\u7684&nbsp;.json&nbsp;\u6587\u4ef6\u4e2d\uff0c\u5f15\u5165\u7ec4\u4ef6\n{\n&nbsp;&nbsp;\"usingComponents\":&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;\"my-test\":&nbsp;\"\/components\/test\/test\"\n&nbsp;&nbsp;}\n}\n#&nbsp;\u5728\u9875\u9762\u7684&nbsp;.wxml&nbsp;\u6587\u4ef6\u4e2d\uff0c\u4f7f\u7528\u7ec4\u4ef6\n&lt;my-test&gt;&lt;\/my-test&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>1.4\u3001\u5168\u5c40\u5f15\u7528\u7ec4\u4ef6<\/strong><\/span><\/p>\n<p>\u5728 app.json \u5168\u5c40\u914d\u7f6e\u6587\u4ef6\u4e2d\u5f15\u7528\u7ec4\u4ef6\u7684\u65b9\u5f0f\uff0c\u53eb\u505a\u5168\u5c40\u5f15\u7528\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>#&nbsp;\u5728&nbsp;app.json&nbsp;\u6587\u4ef6\u4e2d\uff0c\u5f15\u5165\u7ec4\u4ef6\n{\n&nbsp;&nbsp;\"usingComponents\":&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;\"my-test\":&nbsp;\"\/components\/test\/test\"\n&nbsp;&nbsp;}\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>1.5\u3001\u5168\u5c40\u5f15\u7528 VS \u5c40\u90e8\u5f15\u7528<\/strong><\/span><\/p>\n<p>\u6839\u636e\u7ec4\u4ef6\u7684\u4f7f\u7528\u9891\u7387\u548c\u8303\u56f4\uff0c\u6765\u9009\u62e9\u5408\u9002\u7684\u5f15\u7528\u65b9\u5f0f\uff1a<\/p>\n<ul>\n<li>\n<p>\u5982\u679c\u67d0\u7ec4\u4ef6\u5728\u591a\u4e2a\u9875\u9762\u4e2d\u7ecf\u5e38\u88ab\u7528\u5230\uff0c\u5efa\u8bae\u8fdb\u884c\u5168\u5c40\u5f15\u7528<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u67d0\u7ec4\u4ef6\u53ea\u5728\u7279\u5b9a\u7684\u9875\u9762\u4e2d\u88ab\u7528\u5230\uff0c\u5efa\u8bae\u8fdb\u884c\u5c40\u90e8\u5f15\u7528<\/p>\n<\/li>\n<\/ul>\n<p><span style=\"font-size: 18px\"><strong>1.6\u3001\u7ec4\u4ef6\u548c\u9875\u9762\u7684\u533a\u522b<\/strong><\/span><\/p>\n<p>\u4ece\u8868\u9762\u6765\u770b\uff0c\u7ec4\u4ef6\u548c\u9875\u9762\u90fd\u662f\u7531 .js\u3001.json\u3001.wxml \u548c .wxss \u8fd9\u56db\u4e2a\u6587\u4ef6\u7ec4\u6210\u7684\u3002\u4f46\u662f\uff0c\u7ec4\u4ef6\u548c\u9875\u9762\u7684 .js \u4e0e .json \u6587\u4ef6\u6709\u660e\u663e\u7684\u4e0d\u540c\uff1a<\/p>\n<ul>\n<li>\n<p>\u7ec4\u4ef6\u7684 .json \u6587\u4ef6\u4e2d\u9700\u8981\u58f0\u660e &#8220;component&#8221;: true \u5c5e\u6027<\/p>\n<\/li>\n<li>\n<p>\u7ec4\u4ef6\u7684 .js \u6587\u4ef6\u4e2d\u8c03\u7528\u7684\u662f Component() \u51fd\u6570<\/p>\n<\/li>\n<li>\n<p>\u7ec4\u4ef6\u7684\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u9700\u8981\u5b9a\u4e49\u5230 methods \u8282\u70b9\u4e2d<\/p>\n<\/li>\n<\/ul>\n<h2><strong>2\u3001\u6837\u5f0f\u9694\u79bb<\/strong><\/h2>\n<p><span style=\"font-size: 18px\"><strong>2.1\u3001\u7ec4\u4ef6\u6837\u5f0f\u9694\u79bb<\/strong><\/span><\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684\u6837\u5f0f\u53ea\u5bf9\u5f53\u524d\u7ec4\u4ef6\u751f\u6548\uff0c\u4e0d\u4f1a\u5f71\u54cd\u5230\u7ec4\u4ef6\u4e4b\u5916\u7684 UI \u7ed3\u6784\u3002<\/p>\n<p>\u9632\u6b62\u5916\u754c\u7684\u6837\u5f0f\u5f71\u54cd\u7ec4\u4ef6\u5185\u90e8\u7684\u6837\u5f0f<\/p>\n<p>\u9632\u6b62\u7ec4\u4ef6\u7684\u6837\u5f0f\u7834\u574f\u5916\u754c\u7684\u6837\u5f0f<\/p>\n<p><span style=\"font-size: 18px\"><strong>2.2\u3001\u7ec4\u4ef6\u6837\u5f0f\u9694\u79bb\u7684\u6ce8\u610f\u70b9<\/strong><\/span><\/p>\n<p>app.wxss \u4e2d\u7684\u5168\u5c40\u6837\u5f0f\u5bf9\u7ec4\u4ef6\u65e0\u6548<\/p>\n<p>\u53ea\u6709 class \u9009\u62e9\u5668\u4f1a\u6709\u6837\u5f0f\u9694\u79bb\u6548\u679c\uff0cid \u9009\u62e9\u5668\u3001\u5c5e\u6027\u9009\u62e9\u5668\u3001\u6807\u7b7e\u9009\u62e9\u5668\u4e0d\u53d7\u6837\u5f0f\u9694\u79bb\u5f71\u54cd<\/p>\n<p>\u5728\u7ec4\u4ef6\u548c\u5f15\u7528\u7ec4\u4ef6\u7684\u9875\u9762\u4e2d\u5efa\u8bae\u4f7f\u7528 class \u9009\u62e9\u5668\uff0c\u4e0d\u8981\u4f7f\u7528 id\u3001\u5c5e\u6027\u3001\u6807\u7b7e\u9009\u62e9\u5668<\/p>\n<p><span style=\"font-size: 18px\"><strong>2.3\u3001\u4fee\u6539\u7ec4\u4ef6\u7684\u6837\u5f0f\u9694\u79bb\u9009\u9879<\/strong><\/span><\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684\u6837\u5f0f\u9694\u79bb\u7279\u6027\u80fd\u591f\u9632\u6b62\u7ec4\u4ef6\u5185\u5916\u6837\u5f0f\u4e92\u76f8\u5e72\u6270\u7684\u95ee\u9898\u3002\u4f46\u6709\u65f6\uff0c\u6211\u4eec\u5e0c\u671b\u5728\u5916\u754c\u80fd\u591f\u63a7\u5236\u7ec4\u4ef6\u5185\u90e8\u7684\u6837\u5f0f\u3002\u6b64\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7 stylelsolation \u4fee\u6539\u7ec4\u4ef6\u7684\u6837\u5f0f\u9694\u79bb\u9009\u9879\uff0c\u7528\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>#&nbsp;\u5728\u7ec4\u4ef6\u7684&nbsp;.js&nbsp;\u6587\u4ef6\u4e2d\u65b0\u589e\u5982\u4e0b\u914d\u7f6e\nComponent({\n&nbsp;&nbsp;options:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;stylelsolation:&nbsp;'isolated'\n&nbsp;&nbsp;}\n})\n#&nbsp;\u6216\u5728\u7ec4\u4ef6\u7684&nbsp;.json&nbsp;\u6587\u4ef6\u4e2d\u65b0\u589e\u5982\u4e0b\u914d\u7f6e\n{\n&nbsp;&nbsp;\"stylelsolation\":&nbsp;\"isolated\"\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>2.4\u3001stylelsolation \u7684\u53ef\u9009\u503c<\/strong><\/span><\/p>\n<p>|&nbsp; &nbsp; \u53ef\u9009\u503c&nbsp; &nbsp; | \u9ed8\u8ba4\u503c | \u63cf\u8ff0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|<\/p>\n<p>| :&#8212;&#8212;&#8212;-: | :&#8212;-: | &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; | &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; |<\/p>\n<p>|&nbsp; &nbsp;isolated&nbsp; &nbsp;|&nbsp; &nbsp;\u662f&nbsp; &nbsp;| \u8868\u793a\u542f\u7528\u6837\u5f0f\u9694\u79bb&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| \u8868\u793a\u542f\u7528\u6837\u5f0f\u9694\u79bb\uff0c\u5728\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u5185\u5916\uff0c\u4f7f\u7528 class \u6307\u5b9a\u7684\u6837\u5f0f\u5c06\u4e0d\u4f1a\u4e92\u76f8\u5f71\u54cd |<\/p>\n<p>| apply-shared |&nbsp; &nbsp;\u5426&nbsp; &nbsp;| \u8868\u793a\u9875\u9762 wxss \u6837\u5f0f\u5c06\u5f71\u54cd\u5230\u81ea\u5b9a\u4e49\u7ec4\u4ef6\uff0c\u4f46\u81ea\u5b9a\u4e49\u7ec4\u4ef6 wxss \u4e2d\u6307\u5b9a\u7684\u6837\u5f0f\u4e0d\u4f1a\u5f71\u54cd\u9875\u9762&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|<\/p>\n<p>|&nbsp; &nbsp; shared&nbsp; &nbsp; |&nbsp; &nbsp;\u5426&nbsp; &nbsp;| \u8868\u793a\u9875\u9762 wxss \u6837\u5f0f\u5c06\u5f71\u54cd\u5230\u81ea\u5b9a\u4e49\u7ec4\u4ef6\uff0c\u81ea\u5b9a\u4e49\u7ec4\u4ef6 wxss \u4e2d\u6307\u5b9a\u7684\u6837\u5f0f\u4e5f\u4f1a\u5f71\u54cd\u9875\u9762\u548c\u5176\u4ed6\u8bbe\u7f6e\u4e86 apply-shared \u6216 shared \u7684\u81ea\u5b9a\u4e49\u7ec4\u4ef6 |<\/p>\n<h2>3\u3001\u6570\u636e\u3001\u65b9\u6cd5\u548c\u5c5e\u6027<\/h2>\n<p><span style=\"font-size: 18px\"><strong>3.1\u3001data \u6570\u636e<\/strong><\/span><\/p>\n<p>\u5728\u5c0f\u7a0b\u5e8f\u7ec4\u4ef6\u4e2d\uff0c\u7528\u4e8e\u7ec4\u4ef6\u6a21\u677f\u6e32\u67d3\u548c\u79c1\u6709\u6570\u636e\uff0c\u9700\u8981\u5b9a\u4e49\u5230 data \u8282\u70b9\u4e2d\uff0c\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre>Component({\n&nbsp;&nbsp;&lt;!-- \u7ec4\u4ef6\u7684\u521d\u59cb\u6570\u636e --&gt;\n&nbsp;&nbsp;data:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;count:&nbsp;0\n&nbsp;&nbsp;}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>3.2\u3001methods \u6570\u636e<\/strong><\/span><\/p>\n<p>\u5728\u5c0f\u7a0b\u5e8f\u7ec4\u4ef6\u4e2d\uff0c\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u548c\u81ea\u5b9a\u4e49\u65b9\u6cd5\u9700\u8981\u5b9a\u4e49\u5230 methods \u8282\u70b9\u4e2d\uff0c\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>Component({\n&nbsp;&nbsp;&nbsp;&lt;!-- \u7ec4\u4ef6\u7684\u65b9\u6cd5\u5217\u8868 --&gt;\n&nbsp;&nbsp;methods:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;!-- \u4e8b\u4ef6\u5904\u7406\u51fd\u6570 --&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;addCount()&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setData({count:&nbsp;this.data.count&nbsp;+&nbsp;1});\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!-- \u901a\u8fc7 this \u76f4\u63a5\u8c03\u7528\u81ea\u5b9a\u4e49\u65b9\u6cd5 --&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this._showCount()\n&nbsp;&nbsp;&nbsp;&nbsp;},\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;!-- \u81ea\u5b9a\u4e49\u65b9\u6cd5\u5efa\u8bae\u4ee5 _ \u5f00\u5934 --&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;_showCount()&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wx.showToast({\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;title:&nbsp;'count\u503c\u4e3a\uff1a'&nbsp;+&nbsp;this.data.count,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;icon:&nbsp;'none'\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;})\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>3.3\u3001properties \u5c5e\u6027<\/strong><\/span><\/p>\n<p>\u5728\u5c0f\u7a0b\u5e8f\u7ec4\u4ef6\u4e2d\uff0cproperties \u662f\u7ec4\u4ef6\u7684\u5bf9\u5916\u5c5e\u6027\uff0c\u7528\u6765\u63a5\u6536\u5916\u754c\u4f20\u9012\u5230\u7ec4\u4ef6\u4e2d\u7684\u6570\u636e\uff0c\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>Component({\n&nbsp;&nbsp;&lt;!-- \u5c5e\u6027\u5b9a\u4e49 --&gt;\n&nbsp;&nbsp;properties:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;!-- \u5b8c\u6574\u5b9a\u4e49\u5c5e\u6027\u7684\u65b9\u5f0f --&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;max:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;Number,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value:&nbsp;10\n&nbsp;&nbsp;&nbsp;&nbsp;},\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;!-- \u7b80\u5316\u5b9a\u4e49\u5c5e\u6027\u7684\u65b9\u5f0f --&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;max:&nbsp;Number\n&nbsp;&nbsp;}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>3.4\u3001data \u548c properties \u7684\u533a\u522b<\/strong><\/span><\/p>\n<p>\u5728\u5c0f\u7a0b\u5e8f\u7684\u7ec4\u4ef6\u4e2d\uff0cproperties \u5c5e\u6027\u548c data \u6570\u636e\u7684\u7528\u6cd5\u76f8\u540c\uff0c\u5b83\u4eec\u90fd\u662f\u53ef\u8bfb\u53ef\u5199\u7684\uff0c\u53ea\u4e0d\u8fc7\uff1a<\/p>\n<ul>\n<li>\n<p>data \u66f4\u503e\u5411\u4e8e\u5b58\u50a8\u7ec4\u4ef6\u7684\u79c1\u6709\u6570\u636e<\/p>\n<\/li>\n<li>\n<p>properties \u66f4\u503e\u5411\u4e8e\u5b58\u50a8\u5916\u754c\u4f20\u9012\u5230\u7ec4\u4ef6\u4e2d\u7684\u6570\u636e<\/p>\n<\/li>\n<\/ul>\n<pre>Component({\n&nbsp;&nbsp;methods:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;showInfo()&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!-- \u7ed3\u679c\u4e3a true\uff0c\u8bc1\u660e data \u6570\u636e\u548c properties \u5c5e\u6027\u672c\u8d28\u4e0a\u662f\u4e00\u6837\u7684\uff0c\u90fd\u662f\u53ef\u8bfb\u53ef\u5199\u7684 --&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(this.data&nbsp;===&nbsp;this.properties)\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>3.5\u3001\u4f7f\u7528 setData \u4fee\u6539 properties \u7684\u503c<\/strong><\/span><\/p>\n<p>\u7531\u4e8e data \u6570\u636e\u548c properties \u5c5e\u6027\u5728\u672c\u8d28\u4e0a\u6ca1\u6709\u4efb\u4f55\u533a\u522b\uff0c\u56e0\u6b64 properties \u5c5e\u6027\u7684\u503c\u4e5f\u53ef\u4ee5\u7528\u4e8e\u9875\u9762\u6e32\u67d3\uff0c\u6216\u4f7f\u7528 setData \u4e3a properties \u4e2d\u7684\u5c5e\u6027\u91cd\u65b0\u8d4b\u503c\uff0c\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>#&nbsp;\u5728\u7ec4\u5efa\u7684&nbsp;.wxml&nbsp;\u6587\u4ef6\u4e2d\u4f7f\u7528&nbsp;properties&nbsp;\u5c5e\u6027\u7684\u503c\n&lt;view&gt;max\u5c5e\u6027\u7684\u503c\u4e3a\uff1a{{max}}&lt;\/view&gt;\nComponent({\n&nbsp;&nbsp;properties:&nbsp;{&nbsp;max:&nbsp;Number&nbsp;},\n&nbsp;&nbsp;methods:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;addCount()&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setData({&nbsp;max:&nbsp;this.properties.max&nbsp;+&nbsp;1&nbsp;})\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2>4\u3001\u6570\u636e\u76d1\u542c\u5668<\/h2>\n<p><span style=\"font-size: 18px\"><strong>4.1\u3001\u4ec0\u4e48\u662f\u6570\u636e\u76d1\u542c\u5668<\/strong><\/span><\/p>\n<p>\u6570\u636e\u76d1\u542c\u5668\u7528\u4e8e\u76d1\u542c\u548c\u54cd\u5e94\u4efb\u4f55\u5c5e\u6027\u548c\u6570\u636e\u5b57\u6bb5\u7684\u53d8\u5316\uff0c\u4ece\u800c\u6267\u884c\u7279\u5b9a\u7684\u64cd\u4f5c\u3002\u5b83\u7684\u4f5c\u7528\u7c7b\u4f3c\u4e8e vue \u4e2d\u7684 watch \u4fa6\u542c\u5668\u3002\u5728\u5c0f\u7a0b\u5e8f\u7ec4\u4ef6\u4e2d\uff0c\u6570\u636e\u76d1\u542c\u5668\u7684\u57fa\u672c\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre>Component({\n&nbsp;&nbsp;observers:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;'\u5b57\u6bb5A,&nbsp;\u5b57\u6bb5B':&nbsp;function(\u5b57\u6bb5A\u7684\u5fc3\u667a,&nbsp;\u5b57\u6bb5B\u7684\u65b0\u503c)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>4.2\u3001\u6570\u636e\u76d1\u542c\u5668\u7684\u57fa\u672c\u7528\u6cd5<\/strong><\/span><\/p>\n<pre>Component({\n&nbsp;&nbsp;data:&nbsp;{&nbsp;n1:&nbsp;0,&nbsp;n2:&nbsp;0,&nbsp;sum:&nbsp;0&nbsp;},\n&nbsp;&nbsp;methods:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;addN1()&nbsp;{&nbsp;sthis.setData({&nbsp;n1:&nbsp;this.data.n1&nbsp;+&nbsp;1&nbsp;})},\n&nbsp;&nbsp;&nbsp;&nbsp;addN2()&nbsp;{&nbsp;sthis.setData({&nbsp;n2:&nbsp;this.data.n2&nbsp;+&nbsp;1&nbsp;})}\n&nbsp;&nbsp;},\n&nbsp;&nbsp;observers:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;'n1,&nbsp;n2':&nbsp;function(n1,&nbsp;n2)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.setData({sum:&nbsp;n1&nbsp;+&nbsp;n2})\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>4.3\u3001\u76d1\u542c\u5bf9\u8c61\u5c5e\u6027\u7684\u53d8\u5316<\/strong><\/span><\/p>\n<pre>#&nbsp;\u6570\u636e\u76d1\u542c\u5668\u652f\u6301\u76d1\u542c\u5bf9\u8c61\u4e2d\u5355\u4e2a\u6216\u591a\u4e2a\u5c5e\u6027\u7684\u53d8\u5316\uff0c\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a\nComponent({\n&nbsp;&nbsp;observers:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;'\u5bf9\u8c61.\u5c5e\u6027A,&nbsp;\u5bf9\u8c61.\u5c5e\u6027B':&nbsp;function(\u5c5e\u6027A\u7684\u65b0\u503c,&nbsp;\u5c5e\u6027B\u7684\u5fc3\u667a){}\n&nbsp;&nbsp;}\n})\n#&nbsp;\u76d1\u542c\u5bf9\u8c61\u4e2d\u6240\u6709\u5c5e\u6027\u7684\u53d8\u5316\nComponent({\n&nbsp;&nbsp;observers:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;'obj.**':&nbsp;function(obj){}\n&nbsp;&nbsp;}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2><strong>5\u3001\u7eaf\u6570\u636e\u5b57\u6bb5<\/strong><\/h2>\n<p><span style=\"font-size: 18px\"><strong>5.1\u3001\u4ec0\u4e48\u662f\u7eaf\u6570\u636e\u5b57\u6bb5<\/strong><\/span><\/p>\n<p>\u7eaf\u6570\u636e\u5b57\u6bb5\u6307\u7684\u662f\u90a3\u4e9b\u4e0d\u7528\u4e8e\u754c\u9762\u6e32\u67d3\u7684 data \u5b57\u6bb5\u3002<\/p>\n<p>\u5e94\u7528\u573a\u666f\uff1a\u4f8b\u5982\u6709\u4e9b\u60c5\u51b5\u4e0b\uff0c\u67d0\u4e9b data \u4e2d\u7684\u5b57\u6bb5\u65e2\u4e0d\u4f1a\u5c55\u793a\u5728\u754c\u9762\u4e0a\uff0c\u4e5f\u4e0d\u4f1a\u4f20\u9012\u7ed9\u5176\u4ed6\u7ec4\u4ef6\uff0c\u4ec5\u4ec5\u5728\u5f53\u524d\u7ec4\u4ef6\u5185\u90e8\u4f7f\u7528\u3002\u5e26\u6709\u8fd9\u79cd\u7279\u6027\u7684 data \u5b57\u6bb5\u9002\u5408\u5907\u8bbe\u7f6e\u4e3a\u50a8\u6570\u636e\u5b57\u6bb5<\/p>\n<p>\u597d\u5904\uff1a\u7eaf\u6570\u636e\u5b57\u6bb5\u6709\u52a9\u4e8e\u63d0\u5347\u9875\u9762\u66f4\u65b0\u7684\u6027\u80fd<\/p>\n<p><span style=\"font-size: 18px\"><strong>5.2\u3001\u4f7f\u7528\u89c4\u5219<\/strong><\/span><\/p>\n<p>\u5728 Component \u6784\u9020\u5668\u7684 options \u8282\u70b9\u4e2d\uff0c\u6307\u5b9a pureDataPattern \u4e3a\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u5b57\u6bb5\u540d\u7b26\u5408\u8fd9\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5b57\u6bb5\u5c06\u6210\u4e3a\u7eaf\u6570\u636e\u5b57\u6bb5\uff0c\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>Component({\n&nbsp;&nbsp;options:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;!-- \u6307\u5b9a\u6240\u6709 _ \u5f00\u5934\u7684\u6570\u636e\u5b57\u6bb5\u4e3a\u7eaf\u6570\u636e\u5b57\u6bb5 --&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;pureDataPattern:&nbsp;\/^_\/\n&nbsp;&nbsp;},\n&nbsp;&nbsp;data:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;a:&nbsp;true,&nbsp;\/\/&nbsp;\u666e\u901a\u6570\u636e\u5b57\u6bb5\n&nbsp;&nbsp;&nbsp;&nbsp;_b:&nbsp;true&nbsp;\/\/&nbsp;\u7eaf\u6570\u636e\u5b57\u6bb5\n&nbsp;&nbsp;}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2><strong>6\u3001\u7ec4\u4ef6\u7684\u751f\u547d\u5468\u671f<\/strong><\/h2>\n<p><span style=\"font-size: 18px\"><strong>6.1\u3001\u7ec4\u4ef6\u7684\u5168\u90e8\u751f\u547d\u5468\u671f\u51fd\u6570<\/strong><\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/879\/512\/810\/1665639972250719.png\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u57fa\u7840\u52a0\u5f3a\u603b\u7ed3\u63d2\u56fe1\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u57fa\u7840\u52a0\u5f3a\u603b\u7ed3\u63d2\u56fe1\" \/><\/p>\n<p><span style=\"font-size: 18px\"><strong>6.2\u3001\u7ec4\u4ef6\u4e3b\u8981\u7684\u751f\u547d\u5468\u671f\u51fd\u6570<\/strong><\/span><\/p>\n<p>\u5728\u5c0f\u7a0b\u5e8f\u7ec4\u4ef6\u4e2d\uff0c\u6700\u91cd\u8981\u7684\u751f\u547d\u5468\u671f\u51fd\u6570\u6709 3 \u4e2a\uff0c\u5206\u522b\u662f created\u3001attached\u3001detached\u3002\u5b83\u4eec\u5404\u81ea\u7684\u7279\u70b9\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\n<p>\u7ec4\u4ef6\u5b9e\u4f8b\u521a\u88ab\u521b\u5efa\u597d\u7684\u65f6\u5019\uff0ccreated \u751f\u547d\u5468\u671f\u51fd\u6570\u4f1a\u88ab\u89e6\u53d1<\/p>\n<\/li>\n<\/ul>\n<p>\u6b64\u65f6\u8fd8\u4e0d\u80fd\u8c03\u7528 setData<\/p>\n<p>\u901a\u5e38\u5728\u8fd9\u4e2a\u751f\u547d\u5468\u671f\u51fd\u6570\u4e2d\uff0c\u53ea\u5e94\u8be5\u7528\u4e8e\u7ed9\u7ec4\u4ef6\u7684 this \u6dfb\u52a0\u4e00\u4e9b\u81ea\u5b9a\u4e49\u7684\u5c5e\u6027\u5b57\u6bb5<\/p>\n<ul>\n<li>\n<p>\u5728\u7ec4\u5efa\u5b8c\u5168\u521d\u59cb\u5316\u5b8c\u6bd5\u3001\u8fdb\u5165\u9875\u9762\u8282\u70b9\u6811\u540e\uff0cattached \u751f\u547d\u5468\u671f\u51fd\u6570\u4f1a\u88ab\u89e6\u53d1<\/p>\n<\/li>\n<\/ul>\n<p>\u6b64\u65f6\uff0cthis.data \u5df2\u88ab\u521d\u59cb\u5316\u5b8c\u6bd5<\/p>\n<p>\u8fd9\u4e2a\u751f\u547d\u5468\u671f\u5f88\u6709\u7528\uff0c\u7edd\u5927\u591a\u6570\u521d\u59cb\u5316\u7684\u5de5\u4f5c\u53ef\u4ee5\u5728\u8fd9\u4e2a\u65f6\u673a\u8fdb\u884c<\/p>\n<ul>\n<li>\n<p>\u7ec4\u4ef6\u79bb\u5f00\u9875\u9762\u8282\u70b9\u6811\u540e\uff0cdetached \u751f\u547d\u5468\u671f\u51fd\u6570\u4f1a\u88ab\u89e6\u53d1<\/p>\n<\/li>\n<\/ul>\n<p>\u9000\u51fa\u4e00\u4e2a\u9875\u9762\u65f6\uff0c\u4f1a\u89e6\u53d1\u9875\u9762\u5185\u6bcf\u4e2a\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684 detached \u751f\u547d\u5468\u671f\u51fd\u6570<\/p>\n<p>\u6b64\u65f6\u9002\u5408\u505a\u4e00\u4e9b\u6e05\u7406\u6027\u8d28\u7684\u5de5\u4f5c<\/p>\n<p><span style=\"font-size: 18px\"><strong>6.3\u3001lifetimes \u8282\u70b9<\/strong><\/span><\/p>\n<p>\u5728\u5c0f\u7a0b\u5e8f\u7ec4\u4ef6\u4e2d\uff0c\u751f\u547d\u5468\u671f\u51fd\u6570\u53ef\u4ee5\u76f4\u63a5\u5b9a\u4e49\u5728 Component \u6784\u9020\u5668\u7684\u7b2c\u4e00\u7ea7\u53c2\u6570\u4e2d\uff0c\u53ef\u4ee5\u5728 lifetimes \u5b57\u6bb5\u5185\u8fdb\u884c\u58f0\u660e\uff08\u8fd9\u662f\u63a8\u8350\u7684\u65b9\u5f0f\uff0c\u5176\u4f18\u5148\u7ea7\u6700\u9ad8\uff09\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>Component({\n&nbsp;&nbsp;&lt;!-- \u63a8\u8350\u7528\u6cd5 --&gt;\n&nbsp;&nbsp;lifetimes:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;attached()&nbsp;{},&nbsp;\/\/&nbsp;\u5728\u7ec4\u4ef6\u5b9e\u4f8b\u8fdb\u5165\u9875\u9762\u8282\u70b9\u6811\u65f6\u6267\u884c\n&nbsp;&nbsp;&nbsp;&nbsp;detached()&nbsp;{},&nbsp;\/\/&nbsp;\u5728\u7ec4\u4ef6\u5b9e\u4f8b\u88ab\u4ece\u9875\u9762\u8282\u70b9\u6811\u79fb\u9664\u65f6\u6267\u884c\n&nbsp;&nbsp;},\n&nbsp;&nbsp;&lt;!-- \u4ee5\u4e0b\u662f\u65e7\u7684\u5b9a\u4e49\u65b9\u5f0f --&gt;\n&nbsp;&nbsp;attached()&nbsp;{},&nbsp;\/\/&nbsp;\u5728\u7ec4\u4ef6\u5b9e\u4f8b\u8fdb\u5165\u9875\u9762\u8282\u70b9\u6811\u65f6\u6267\u884c\n&nbsp;&nbsp;detached()&nbsp;{},&nbsp;\/\/&nbsp;\u5728\u7ec4\u4ef6\u5b9e\u4f8b\u88ab\u4ece\u9875\u9762\u8282\u70b9\u6811\u79fb\u9664\u65f6\u6267\u884c\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>6.4\u3001\u4ec0\u4e48\u662f\u7ec4\u4ef6\u6240\u5728\u9875\u9762\u7684\u751f\u547d\u5468\u671f<\/strong><\/span><\/p>\n<p>\u6709\u65f6\uff0c\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684\u884c\u4e3a\u4f9d\u8d56\u4e8e\u9875\u9762\u72b6\u6001\u7684\u53d8\u5316\uff0c\u6b64\u65f6\u5c31\u9700\u8981\u7528\u5230\u7ec4\u4ef6\u6240\u5728\u9875\u9762\u7684\u751f\u547d\u5468\u671f<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/267\/860\/434\/1665640009784824.png\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u57fa\u7840\u52a0\u5f3a\u603b\u7ed3\u63d2\u56fe2\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u57fa\u7840\u52a0\u5f3a\u603b\u7ed3\u63d2\u56fe2\" \/><\/p>\n<p><span style=\"font-size: 18px\"><strong>6.5\u3001pageLifetimes \u8282\u70b9<\/strong><\/span><\/p>\n<pre>#&nbsp;\u7ec4\u4ef6\u6240\u5728\u9875\u9762\u7684\u751f\u547d\u5468\u671f\u51fd\u6570\uff0c\u9700\u8981\u5b9a\u4e49\u5728&nbsp;pageLifetimes&nbsp;\u8282\u70b9\u4e2d\nComponent({\n&nbsp;&nbsp;pageLifetimes:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;show:&nbsp;function()&nbsp;{},&nbsp;\/\/&nbsp;\u9875\u9762\u88ab\u5c55\u793a\n&nbsp;&nbsp;&nbsp;&nbsp;hide:&nbsp;function()&nbsp;{},&nbsp;\/\/&nbsp;\u9875\u9762\u88ab\u9690\u85cf\n&nbsp;&nbsp;&nbsp;&nbsp;resize:&nbsp;function(size)&nbsp;{}&nbsp;\/\/&nbsp;\u9875\u9762\u5c3a\u5bf8\u53d8\u5316\n&nbsp;&nbsp;}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2>7\u3001\u63d2\u69fd<\/h2>\n<p><span style=\"font-size: 18px\"><strong>7.1\u3001\u4ec0\u4e48\u662f\u63d2\u69fd<\/strong><\/span><\/p>\n<p>\u5728\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684 wxml \u7ed3\u6784\u4e2d\uff0c\u53ef\u4ee5\u63d0\u4f9b\u4e00\u4e2a slot \u8282\u70b9\uff08\u63d2\u69fd\uff09\uff0c\u7528\u4e8e\u627f\u8f7d\u7ec4\u4ef6\u4f7f\u7528\u8005\u63d0\u4f9b\u7684 wxml \u7ed3\u6784\u3002<\/p>\n<p><span style=\"font-size: 18px\"><strong>7.2\u3001\u5355\u4e2a\u63d2\u69fd<\/strong><\/span><\/p>\n<p>\u5728\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u9ed8\u8ba4\u6bcf\u4e2a\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u4e2d\u53ea\u5141\u8bb8\u4f7f\u7528\u4e00\u4e2a slot \u8fdb\u884c\u5360\u4f4d\uff0c\u8fd9\u79cd\u4e2a\u6570\u4e0a\u9650\u5236\u53eb\u505a\u5355\u4e2a\u63d2\u69fd<\/p>\n<pre>&lt;!-- \u7ec4\u4ef6\u7684\u5c01\u88c5\u8005 --&gt;\n&lt;view&gt;\n&nbsp;&nbsp;&lt;view&gt;\u8fd9\u91cc\u662f\u7ec4\u4ef6\u7684\u5185\u90e8\u8282\u70b9&lt;\/view&gt;\n&nbsp;&nbsp;&lt;!-- \u5bf9\u4e8e\u4e0d\u51c6\u786e\u7684\u5185\u5bb9\uff0c\u53ef\u4ee5\u4f7f\u7528 slot \u8fdb\u884c\u5c55\u4f4d --&gt;\n&nbsp;&nbsp;&lt;slot&gt;&lt;\/slot&gt;&lt;\/view&gt;&lt;!-- \u7ec4\u4ef6\u7684\u4f7f\u7528\u8005 --&gt;&lt;component&gt;\n&nbsp;&nbsp;&lt;view&gt;\u8fd9\u91cc\u662f\u63d2\u5165\u5230\u7ec4\u4ef6slot\u4e2d\u7684\u5185\u5bb9&lt;\/view&gt;&lt;\/component&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>7.3\u3001\u542f\u7528\u591a\u4e2a\u63d2\u69fd<\/strong><\/span><\/p>\n<p>\u5728\u5c0f\u7a0b\u5e8f\u7684\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u4e2d\uff0c\u9700\u8981\u4f7f\u7528\u591a\u4e2a slot \u63d2\u69fd\u662f\uff0c\u53ef\u4ee5\u5728\u7ec4\u4ef6\u7684 .js \u6587\u4ef6\u4e2d\uff0c\u901a\u8fc7\u5982\u4e0b\u65b9\u5f0f\u8fdb\u884c\u542f\u7528\uff0c\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>Component({\n&nbsp;&nbsp;options:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;multipleSlots:&nbsp;true&nbsp;\/\/&nbsp;\u5728\u7ec4\u4ef6\u5b9a\u4e49\u65f6\uff0c\u542f\u7528\u591a\u4e2a&nbsp;slot&nbsp;\u652f\u6301\n&nbsp;&nbsp;}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>7.4\u3001\u5b9a\u4e49\u591a\u4e2a\u63d2\u69fd<\/strong><\/span><\/p>\n<p>\u53ef\u4ee5\u5728\u7ec4\u4ef6\u7684 .wxml \u4e2d\u4f7f\u7528\u591a\u4e2a slot \u6807\u7b7e\uff0c\u4ee5\u4e0d\u540c\u7684 name \u6765\u533a\u5206\u4e0d\u540c\u7684\u63d2\u69fd\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>&lt;!-- \u7ec4\u4ef6\u6a21\u677f --&gt;\n&lt;view&gt;\n&nbsp;&nbsp;&lt;!-- name \u4e3a before \u7684\u7b2c\u4e00\u4e2a slot \u63d2\u69fd --&gt;\n&nbsp;&nbsp;&lt;slot&gt;&lt;\/slot&gt;\n&nbsp;&nbsp;&lt;view&gt;\u8fd9\u662f\u4e00\u6bb5\u56fa\u5b9a\u7684\u6587\u672c\u5185\u5bb9&lt;\/view&gt;\n&nbsp;&nbsp;&lt;!-- name \u4e3a after \u7684\u7b2c\u4e8c\u4e2a slot \u63d2\u69fd --&gt;\n&nbsp;&nbsp;&lt;slot&gt;&lt;\/slot&gt;&lt;\/view&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>7.5\u3001\u4f7f\u7528\u591a\u4e2a\u63d2\u69fd<\/strong><\/span><\/p>\n<p>\u5728\u4f7f\u7528\u5e26\u6709\u591a\u4e2a\u63d2\u69fd\u7684\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u65f6\uff0c\u9700\u8981\u7528 slot \u5c5e\u6027\u6765\u5c06\u8282\u70b9\u63d2\u5165\u5230\u4e0d\u540c\u7684 slot \u4e2d\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>&lt;!-- \u5f15\u7528\u7ec4\u4ef6\u7684\u9875\u9762\u6a21\u677f --&gt;\n&lt;component&gt;\n&nbsp;&nbsp;&lt;!-- \u8fd9\u90e8\u5206\u5185\u5bb9\u5c06\u88ab\u653e\u7f6e\u5728\u7ec4\u4ef6 &lt;slot name=\"before\"&gt;&lt;\/slot&gt; \u7684\u4f4d\u7f6e\u4e0a --&gt;\n&nbsp;&nbsp;&lt;view&gt;\u8fd9\u91cc\u662f\u63d2\u5165\u5230\u7ec4\u4ef6&nbsp;slot&nbsp;name=\"before\"\u4e2d\u7684\u5185\u5bb9&lt;\/view&gt;\n&nbsp;&nbsp;&lt;!-- \u8fd9\u90e8\u5206\u5185\u5bb9\u5c06\u88ab\u653e\u7f6e\u5728\u7ec4\u4ef6 &lt;slot name=\"after\"&gt;&lt;\/slot&gt; \u7684\u4f4d\u7f6e\u4e0a --&gt;\n&nbsp;&nbsp;&lt;view&gt;\u8fd9\u91cc\u662f\u63d2\u5165\u5230\u7ec4\u4ef6&nbsp;slot&nbsp;name=\"after\"\u4e2d\u7684\u5185\u5bb9&lt;\/view&gt;&lt;\/component&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2><strong>8\u3001\u7236\u5b50\u7ec4\u4ef6\u4e4b\u95f4\u7684\u901a\u4fe1<\/strong><\/h2>\n<p><span style=\"font-size: 18px\"><strong>8.1\u3001\u7236\u5b50\u7ec4\u4ef6\u4e4b\u95f4\u7684\u901a\u4fe1\u7684 3 \u79cd\u65b9\u5f0f<\/strong><\/span><\/p>\n<p>\u5c5e\u6027\u7ed1\u5b9a<\/p>\n<p>\u7528\u4e8e\u7236\u7ec4\u4ef6\u5411\u5b50\u7ec4\u4ef6\u7684\u6307\u5b9a\u5c5e\u6027\u8bbe\u7f6e\u6570\u636e\uff0c\u4ec5\u80fd\u8bbe\u7f6e JSON \u517c\u5bb9\u7684\u6570\u636e<\/p>\n<p>\u4e8b\u4ef6\u7ed1\u5b9a<\/p>\n<p>\u7528\u4e8e\u5b50\u7ec4\u4ef6\u5411\u7236\u7ec4\u4ef6\u4f20\u9012\u6570\u636e\uff0c\u53ef\u4ee5\u4f20\u9012\u4efb\u610f\u6570\u636e<\/p>\n<p>\u83b7\u53d6\u7ec4\u4ef6\u5b9e\u4f8b<\/p>\n<p>\u7236\u7ec4\u4ef6\u8fd8\u53ef\u4ee5\u901a\u8fc7 this.selectComponent() \u83b7\u53d6\u5b50\u7ec4\u4ef6\u5b9e\u4f8b\u5bf9\u8c61<\/p>\n<p>\u8fd9\u6837\u65e7\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u5b50\u7ec4\u4ef6\u7684\u4efb\u610f\u6570\u636e\u548c\u65b9\u6cd5<\/p>\n<p><span style=\"font-size: 18px\"><strong>8.2\u3001\u5c5e\u6027\u7ed1\u5b9a<\/strong><\/span><\/p>\n<p>\u5c5e\u6027\u7ed1\u5b9a\u7528\u4e8e\u5b9e\u73b0\u7236\u5411\u5b50\u4f20\u503c\uff0c\u800c\u4e14\u53ea\u80fd\u4f20\u9012\u666e\u901a\u7c7b\u578b\u7684\u6570\u636e\uff0c\u65e0\u6cd5\u5c06\u65b9\u6cd5\u4f20\u9012\u7ed9\u5b50\u7ec4\u4ef6\u3002\u7236\u7ec4\u4ef6\u7684\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>&lt;!-- \u7236\u7ec4\u4ef6\u7684 data \u8282\u70b9 --&gt;\ndata:&nbsp;{\n&nbsp;&nbsp;count:&nbsp;0\n}\n&lt;!-- \u7236\u7ec4\u4ef6\u7684 wxml \u7ed3\u6784 --&gt;\n&lt;my-child&gt;&lt;\/my-child&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<pre>&lt;!-- \u5b50\u7ec4\u4ef6\u7684 properties \u8282\u70b9 --&gt;\nproperties:&nbsp;{\n&nbsp;&nbsp;count:&nbsp;Number\n}\n&lt;!-- \u5b50\u7ec4\u4ef6\u7684 wxml --&gt;\n&lt;view&gt;\u5b50\u7ec4\u4ef6\u79cd\uff0ccount\u503c\u4e3a\uff1a{{count}}&lt;\/view&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>8.3\u3001\u4e8b\u4ef6\u7ed1\u5b9a<\/strong><\/span><\/p>\n<p>\u4e8b\u4ef6\u7ed1\u5b9a\u7528\u4e8e\u5b9e\u73b0\u5b50\u5411\u7236\u4f20\u503c\uff0c\u53ef\u4ee5\u4f20\u9012\u4efb\u4f55\u7c7b\u578b\u7684\u6570\u636e\u3002\u4f7f\u7528\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p>\u5728\u7236\u7ec4\u4ef6\u7684 js \u4e2d\uff0c\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\uff0c\u8fd9\u4e2a\u51fd\u6570\u5373\u5c06\u901a\u8fc7\u81ea\u5b9a\u4e49\u4e8b\u4ef6\u7684\u5f62\u5f0f\uff0c\u4f20\u9012\u7ed9\u5b50\u7ec4\u4ef6<\/p>\n<pre>&lt;!-- \u5728\u7236\u7ec4\u4ef6\u5b9a\u4e49 syncCount \u65b9\u6cd5\uff0c\u5c06\u6765\u4f20\u9012\u7ed9\u5b50\u7ec4\u4ef6\uff0c\u4f9b\u5b50\u7ec4\u4ef6\u8fdb\u884c\u8c03\u7528 --&gt;\nsyncCount()&nbsp;{\n&nbsp;&nbsp;console.log('syncCount')\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u7236\u7ec4\u4ef6\u7684 wxml \u4e2d\uff0c\u901a\u8fc7\u81ea\u5b9a\u4e49\u4e8b\u4ef6\u7684\u5f62\u5f0f\uff0c\u5c06\u6b65\u9aa4 1 \u4e2d\u5b9a\u4e49\u7684\u51fd\u6570\u5f15\u7528\uff0c\u4f20\u9012\u7ed9\u5b50\u7ec4\u4ef6<\/p>\n<pre>&lt;!-- \u4f7f\u7528bind:\u81ea\u5b9a\u4e49\u4e8b\u4ef6\u540d\u79f0\uff08\u63a8\u8350\uff1a\u7ed3\u6784\u6e05\u6670\uff09 --&gt;\n&lt;my-test&gt;&lt;\/my-test&gt;&lt;!-- \u4f7f\u7528bind\u540e\u9762\u76f4\u63a5\u534f\u5546\u81ea\u5b9a\u4e49\u4e8b\u4ef6\u540d\u79f0--&gt;&lt;my-test&gt;&lt;\/my-test&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u5b50\u7ec4\u4ef6\u7684 js \u4e2d\uff0c\u901a\u8fc7\u8c03\u7528 this.triggerEvent(&#8216;\u81ea\u5b9a\u4e49\u4e8b\u4ef6\u540d\u79f0&#8217;,{\u53c2\u6570\u5bf9\u8c61})\uff0c\u5c06\u6570\u636e\u53d1\u9001\u5230\u7236\u7ec4\u4ef6<\/p>\n<pre>&lt;!-- \u5b50\u7ec4\u4ef6\u7684 wxml \u7ed3\u6784 --&gt;\n&lt;text&gt;\u5b50\u7ec4\u4ef6\u4e2d\uff0ccount\uff1a{{count}}&lt;\/text&gt;&lt;button&gt;+1&lt;\/button&gt;\n#&nbsp;\u5b50\u7ec4\u4ef6\u7684&nbsp;js&nbsp;\u4ee3\u7801\nmethods:&nbsp;{\n&nbsp;&nbsp;addCount()&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;this.setData({\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count:&nbsp;this.properties.count&nbsp;+&nbsp;1\n&nbsp;&nbsp;&nbsp;&nbsp;})\n&nbsp;&nbsp;&nbsp;&nbsp;this.triggerEvent('sync',&nbsp;{&nbsp;value:&nbsp;this.properties.count&nbsp;})\n&nbsp;&nbsp;}\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u7236\u7ec4\u4ef6\u7684 js \u4e2d\uff0c\u901a\u8fc7 e.detail \u83b7\u53d6\u5230\u5b50\u7ec4\u4ef6\u4f20\u9012\u8fc7\u6765\u7684\u6570\u636e<\/p>\n<pre>syncCount(e)&nbsp;{\n&nbsp;&nbsp;this.setData({\n&nbsp;&nbsp;&nbsp;&nbsp;count:&nbsp;e.detail.value\n&nbsp;&nbsp;})\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>8.4\u3001\u83b7\u53d6\u7ec4\u4ef6\u5b9e\u4f8b<\/strong><\/span><\/p>\n<p>\u53ef\u5728\u7236\u7ec4\u4ef6\u91cc\u8c03\u7528 this.selectComponent(&#8216;id \u6216 class \u9009\u62e9\u5668&#8217;)\uff0c\u83b7\u53d6\u5b50\u7ec4\u4ef6\u7684\u5b9e\u4f8b\u5bf9\u8c61\uff0c\u4ece\u800c\u76f4\u63a5\u8bbf\u95ee\u5b50\u7ec4\u4ef6\u7684\u4efb\u610f\u6570\u636e\u548c\u65b9\u6cd5\u3002<\/p>\n<pre>&lt;my-component&gt;&lt;\/my-component&gt;&lt;button&gt;\u83b7\u53d6\u5b50\u7ec4\u4ef6\u5b9e\u4f8b&lt;\/button&gt;\n&lt;!-- \u6309\u94ae\u7684 tap \u4e8b\u4ef6\u5904\u7406\u51fd\u6570 --&gt;\ngetChild()&nbsp;{\n&nbsp;&nbsp;&lt;!-- \u53ef\u4ee5\u4f20\u9012 id\u9009\u62e9\u5668\uff0c\u4e5f\u53ef\u4ee5\u4f20\u9012 class \u9009\u62e9\u5668 --&gt;\n&nbsp;&nbsp;const&nbsp;child&nbsp;=&nbsp;this.selectComponent('.test')\n&nbsp;&nbsp;&lt;!-- \u8c03\u7528\u5b50\u7ec4\u4ef6\u7684 setData \u65b9\u6cd5 --&gt;\n&nbsp;&nbsp;child.setData({&nbsp;count:&nbsp;child.properties.count&nbsp;+&nbsp;1&nbsp;})\n&nbsp;&nbsp;&lt;!-- \u8c03\u7528\u5b50\u7ec4\u4ef6\u7684 addCount \u65b9\u6cd5 --&gt;\n&nbsp;&nbsp;child.addCount()\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2><strong>9\u3001behaviors<\/strong><\/h2>\n<p><span style=\"font-size: 18px\"><strong>9.1\u3001\u4ec0\u4e48\u662f behaviors<\/strong><\/span><\/p>\n<p>behaviors \u662f\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u7528\u4e8e\u5b9e\u73b0\u7ec4\u4ef6\u95f4\u4ee3\u7801\u5171\u4eab\u7684\u7279\u6027\uff0c\u7c7b\u4f3c\u4e8e Vue.js \u4e2d\u7684 mixins<\/p>\n<p><span style=\"font-size: 18px\"><strong>9.2\u3001behaviors \u7684\u5de5\u4f5c\u65b9\u5f0f<\/strong><\/span><\/p>\n<p>\u6bcf\u4e2a behavior \u53ef\u4ee5\u5305\u542b\u4e00\u7ec4\u5c5e\u6027\u3001\u6570\u636e\u3001\u751f\u547d\u5468\u671f\u51fd\u6570\u548c\u65b9\u6cd5\u3002\u7ec4\u4ef6\u5f15\u7528\u5b83\u65f6\uff0c\u5b83\u7684\u5c5e\u6027\u3001\u5c5e\u6027\u548c\u65b9\u6cd5\u4f1a\u88ab\u5408\u5e76\u5230\u7ec4\u4ef6\u4e2d\u3002<\/p>\n<p>\u6bcf\u4e2a\u7ec4\u4ef6\u53ef\u4ee5\u5f15\u7528\u591a\u4e2a behavior\uff0cbehavior \u4e5f\u53ef\u4ee5\u5f15\u7528\u5176\u5b83 behavior<\/p>\n<p><span style=\"font-size: 18px\"><strong>9.3\u3001\u521b\u5efa behavior<\/strong><\/span><\/p>\n<p>\u8c03\u7528 Behavior(Object object) \u65b9\u6cd5\u5373\u53ef\u521b\u5efa\u4e00\u4e2a\u5171\u4eab\u7684 behavior \u5b9e\u4f8b\u5bf9\u8c61\uff0c\u4f9b\u6240\u6709\u7684\u7ec4\u4ef6\u4f7f\u7528<\/p>\n<pre>#&nbsp;\u8c03\u7528&nbsp;Behavior()&nbsp;\u65b9\u6cd5\uff0c\u521b\u5efa\u5b9e\u4f8b\u5bf9\u8c61\n#&nbsp;\u5e76\u4f7f\u7528&nbsp;module.exports&nbsp;\u5c06&nbsp;behavior&nbsp;\u5b9e\u4f8b\u5bf9\u8c61\u5171\u4eab\u51fa\u53bb\nmodule.exports&nbsp;=&nbsp;Behavior({\n&nbsp;&nbsp;#&nbsp;\u5c5e\u6027\u8282\u70b9\n&nbsp;&nbsp;properties:&nbsp;{},\n&nbsp;&nbsp;#&nbsp;\u79c1\u6709\u6570\u636e\u8282\u70b9\n&nbsp;&nbsp;data:&nbsp;{},\n&nbsp;&nbsp;#&nbsp;\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u548c\u81ea\u5b9a\u4e49\u65b9\u6cd5\u8282\u70b9\n&nbsp;&nbsp;methods:&nbsp;{}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>9.4\u3001\u5bfc\u5165\u5e76\u4f7f\u7528 behavior<\/strong><\/span><\/p>\n<p>\u5728\u7ec4\u4ef6\u4e2d\uff0c\u4f7f\u7528 require() \u65b9\u6cd5\u5bfc\u5165\u9700\u8981\u7684 behavior\uff0c\u6302\u8f7d\u540e\u5373\u53ef\u8bbf\u95ee behavior \u4e2d\u7684\u6570\u636e\u6216\u65b9\u6cd5\uff0c\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>#&nbsp;\u4f7f\u7528&nbsp;require()&nbsp;\u5bfc\u5165\u9700\u8981\u81ea\u5b9a\u4e49&nbsp;behavior&nbsp;\u6a21\u5757\nconst&nbsp;myBehavior&nbsp;=&nbsp;require('my-behavior')\nComponent({\n&nbsp;&nbsp;&lt;!-- \u5c06\u5bfc\u5165\u7684 behavior \u5b9e\u4f8b\u5bf9\u8c61\uff0c\u6302\u8f7d\u5230 behaviors \u6570\u7ec4\u8282\u70b9\u4e2d\u5373\u53ef\u751f\u6548 --&gt;\n&nbsp;&nbsp;behaviors:&nbsp;[myBehavior]\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size: 18px\"><strong>9.5\u3001behavior \u4e2d\u6240\u6709\u53ef\u7528\u7684\u8282\u70b9<\/strong><\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/888\/294\/729\/1665640061386483.png\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u57fa\u7840\u52a0\u5f3a\u603b\u7ed3\u63d2\u56fe3\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u57fa\u7840\u52a0\u5f3a\u603b\u7ed3\u63d2\u56fe3\" \/><\/p>\n<h2><strong>10\u3001\u4f7f\u7528 npm \u5305<\/strong><\/h2>\n<p><span style=\"font-size: 18px\"><strong>10.1\u3001\u5c0f\u7a0b\u5e8f\u5bf9 npm \u7684\u652f\u6301\u4e0e\u9650\u5236<\/strong><\/span><\/p>\n<p>\u76ee\u524d\uff0c\u5c0f\u7a0b\u5e8f\u5df2\u7ecf\u652f\u6301\u4f7f\u7528 npm \u5b89\u88c5\u7b2c\u4e09\u65b9\u5305\uff0c\u4ece\u800c\u6765\u63d0\u9ad8\u5c0f\u7a0b\u5e8f\u7684\u5f00\u53d1\u6548\u7387\u3002\u4f46\u662f\uff0c\u5728\u5c0f\u7a0b\u5e8f\u4e2d\u4f7f\u7528 npm \u5305\u6709\u5982\u4e0b 3 \u4e2a\u9650\u5236\uff1a<\/p>\n<ul>\n<li>\n<p>\u4e0d\u652f\u6301\u4f9d\u8d56\u4e8e Node.js \u5185\u7f6e\u5e93\u7684\u5305<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u652f\u6301\u4f9d\u8d56\u4e8e\u6d4f\u89c8\u5668\u5185\u7f6e\u5bf9\u8c61\u7684\u5305<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u652f\u6301\u4f9d\u8d56\u4e8e C++ \u63d2\u4ef6\u7684\u5305<\/p>\n<\/li>\n<\/ul>\n<p><span style=\"font-size: 18px\"><strong>10.2\u3001API Promise \u5316<\/strong><\/span><\/p>\n<ul>\n<li>\n<p><strong>\u57fa\u4e8e\u56de\u8c03\u51fd\u6570\u7684\u5f02\u6b65 API \u7684\u7f3a\u70b9<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5c0f\u7a0b\u5e8f\u5b98\u65b9\u63d0\u4f9b\u7684\u5f02\u6b65 API \u90fd\u662f\u57fa\u4e8e\u56de\u8c03\u51fd\u6570\u5b9e\u73b0\u7684\uff0c\u4f8b\u5982\uff0c\u7f51\u7edc\u8bf7\u6c42\u7684 API \u9700\u8981\u6309\u7167\u5982\u4e0b\u7684\u65b9\u5f0f\u8c03\u7528\uff1a<\/p>\n<pre>wx.request({\n&nbsp;&nbsp;method:&nbsp;'',\n&nbsp;&nbsp;url:&nbsp;'',\n&nbsp;&nbsp;data:&nbsp;{},\n&nbsp;&nbsp;success:&nbsp;()&nbsp;=&amp;gt;&nbsp;{}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7f3a\u70b9\uff1a\u5bb9\u6613\u9020\u6210\u56de\u8c03\u5730\u72f1\u7684\u95ee\u9898\uff0c\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3001\u7ef4\u62a4\u6027\u5dee<\/p>\n<ul>\n<li>\n<p><strong>\u4ec0\u4e48\u662f API Promise \u5316<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>API Promise \u5316\uff0c\u6307\u5b9a\u662f\u901a\u8fc7\u989d\u5916\u7684\u914d\u7f6e\uff0c\u5c06\u5b98\u65b9\u63d0\u4f9b\u7684\u3001\u57fa\u4e8e\u56de\u8c03\u51fd\u6570\u7684\u5f02\u6b65 API\uff0c\u5347\u7ea7\u6539\u9020\u4e3a\u57fa\u4e8e Promise \u7684\u5f02\u6b65 API\uff0c\u4ece\u800c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3001\u7ef4\u62a4\u6027\u3001\u907f\u514d\u56de\u8c03\u5730\u72f1\u7684\u95ee\u9898<\/p>\n<ul>\n<li>\n<p><strong>\u5b9e\u73b0 API Promise \u5316<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>\u5728\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u5b9e\u73b0 API Promise \u5316\u4e3b\u8981\u4f9d\u8d56\u4e8e minprogram-api-promise \u8fd9\u4e2a\u7b2c\u4e09\u65b9\u7684 npm \u5305\u3002\u5b83\u7684\u5b89\u88c5\u548c\u4f7f\u7528\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<pre>npm&nbsp;install&nbsp;--save&nbsp;minprogram-api-promise\n#&nbsp;\u5728\u5c0f\u7a0b\u5e8f\u5165\u53e3\u6587\u4ef6\u4e2d\uff08app.js\uff09\uff0c\u53ea\u9700\u8981\u8c03\u7528\u4e00\u6b21&nbsp;promisifyAll()&nbsp;\u65b9\u6cd5\nimport&nbsp;{&nbsp;promisifyAll&nbsp;}&nbsp;from&nbsp;'minprogram-api-promise'\nconst&nbsp;wxp&nbsp;=&nbsp;wx.p&nbsp;=&nbsp;{}\npromisifyAll(wx,&nbsp;wxp)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\n<p><strong>\u8c03\u7528 Promise \u5316\u4e4b\u540e\u7684\u5f02\u6b65 API<\/strong><\/p>\n<\/li>\n<\/ul>\n<pre>#&nbsp;\u9875\u9762\u7684&nbsp;.wxml&nbsp;\u7ed3\u6784\n&lt;button&gt;vant\u6309\u94ae&lt;\/button&gt;\n#&nbsp;\u5728\u9875\u9762\u7684&nbsp;.js&nbsp;\u6587\u4ef6\u4e2d\uff0c\u5b9a\u4e49\u5bf9\u5e94\u7684&nbsp;tap&nbsp;\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\nasync&nbsp;getInfo()&nbsp;{\n&nbsp;&nbsp;const&nbsp;{&nbsp;data:&nbsp;res&nbsp;}&nbsp;=&nbsp;await&nbsp;wx.p.request({\n&nbsp;&nbsp;&nbsp;&nbsp;method:&nbsp;'GET',\n&nbsp;&nbsp;&nbsp;&nbsp;url:&nbsp;'',\n&nbsp;&nbsp;&nbsp;&nbsp;data:&nbsp;{}\n&nbsp;&nbsp;})\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2><strong>11\u3001\u5168\u5c40\u6570\u636e\u5171\u4eab<\/strong><\/h2>\n<p><span style=\"font-size: 18px\"><strong>11.1\u3001\u4ec0\u4e48\u662f\u5168\u5c40\u6570\u636e\u5171\u4eab<\/strong><\/span><\/p>\n<p>\u5168\u5c40\u6570\u636e\u5171\u4eab\uff08\u53c8\u53eb\u505a\uff1a\u72b6\u6001\u7ba1\u7406\uff09\u662f\u4e3a\u4e86\u89e3\u51b3\u7ec4\u4ef6\u4e4b\u95f4\u6570\u636e\u5171\u4eab\u7684\u95ee\u9898<\/p>\n<p>\u5f00\u53d1\u4e2d\u5e38\u7528\u7684\u6570\u636e\u5171\u4eab\u65b9\u6848\u6709\uff1aVuex\u3001Redux\u3001MobX \u7b49<\/p>\n<p><span style=\"font-size: 18px\"><strong>11.2\u3001\u5c0f\u7a0b\u5e8f\u4e2d\u7684\u5168\u5c40\u6570\u636e\u5171\u4eab\u65b9\u6848<\/strong><\/span><\/p>\n<p>\u5728\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u53ef\u4f7f\u7528 mobx-miniprogram \u914d\u5408 mobx-miniprogram-bindings \u5b9e\u73b0\u5168\u5c40\u6570\u636e\u5171\u4eab\u3002\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>\n<p>mobx-miniprogram \u7528\u6765\u521b\u5efa Store \u5b9e\u4f8b\u5bf9\u8c61<\/p>\n<\/li>\n<li>\n<p>mobx-miniprogram-bindings \u7528\u6765\u628a Store \u4e2d\u7684\u5171\u4eab\u6570\u636e\u6216\u65b9\u6cd5\uff0c\u7ed1\u5b9a\u5230\u7ec4\u4ef6\u6216\u9875\u9762\u4e2d\u4f7f\u7528<\/p>\n<\/li>\n<\/ul>\n<p>\u5b89\u88c5 MobX \u76f8\u5173\u7684\u5305<\/p>\n<pre>#&nbsp;\u5728\u9879\u76ee\u8fd0\u884c\u5982\u4e0b\u7684\u547d\u4ee4\uff0c\u5b89\u88c5MobX\u76f8\u5173\u7684\u5305\nnpm&nbsp;install&nbsp;--save&nbsp;mobx-miniprogram&nbsp;mobx-miniprogram-bindings<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6ce8\u610f\uff1aMobX \u76f8\u5173\u7684\u5305\u5b89\u88c5\u5b8c\u6bd5\u4e4b\u540e\uff0c\u8bb0\u5f97\u5220\u9664 miniprogram_npm \u76ee\u5f55\u540e\uff0c\u91cd\u65b0\u6784\u5efa npm<\/p>\n<p>\u521b\u5efa MobX \u7684 Store \u5b9e\u4f8b<\/p>\n<pre>import&nbsp;{&nbsp;observable,&nbsp;action&nbsp;}&nbsp;from&nbsp;'mobx-miniprogram'\nexport&nbsp;const&nbsp;store&nbsp;=&nbsp;observable({\n&nbsp;&nbsp;\/\/&nbsp;\u6570\u636e\u5b57\u6bb5\n&nbsp;&nbsp;numA:&nbsp;1,\n&nbsp;&nbsp;numB:&nbsp;2,\n&nbsp;&nbsp;\/\/\u8ba1\u7b97\u5c5e\u6027\n&nbsp;&nbsp;get&nbsp;sum()&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;this.numA&nbsp;+&nbsp;this.numB\n&nbsp;&nbsp;},\n&nbsp;&nbsp;\/\/&nbsp;actions&nbsp;\u65b9\u6cd5\uff0c\u7528\u6765\u4fee\u6539&nbsp;store&nbsp;\u4e2d\u7684\u6570\u636e\n&nbsp;&nbsp;updateNumA:&nbsp;action(function(step)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;this.numA&nbsp;+=&nbsp;step\n&nbsp;&nbsp;}),\n&nbsp;&nbsp;updateNumB:&nbsp;action(function(step)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;this.numB&nbsp;+=&nbsp;step\n&nbsp;&nbsp;}),\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5c06 Store \u4e2d\u7684\u6210\u5458\u7ed1\u5b9a\u5230\u9875\u9762\u4e2d<\/p>\n<pre>#&nbsp;\u9875\u9762\u7684&nbsp;.js&nbsp;\u6587\u4ef6\nimport&nbsp;{&nbsp;createStoreBindings&nbsp;}&nbsp;from&nbsp;'mobx-miniprogram-bindings'\nimport&nbsp;{&nbsp;store&nbsp;}&nbsp;from&nbsp;'.\/store'\nPage({\n&nbsp;&nbsp;onLoad()&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;this.storeBindings&nbsp;=&nbsp;createStoreBindings(this,&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;store,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fields:&nbsp;['numA',&nbsp;'numB',&nbsp;'sum'],\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;actions:&nbsp;['updateNumA']\n&nbsp;&nbsp;&nbsp;&nbsp;})\n&nbsp;&nbsp;},\n&nbsp;&nbsp;&lt;!-- \u751f\u547d\u5468\u671f\u51fd\u6570--\u76d1\u542c\u9875\u9762\u5378\u8f7d --&gt;\n&nbsp;&nbsp;onUnload()&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;this.storeBindings.destroyBindings()\n&nbsp;&nbsp;}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u9875\u9762\u4e0a\u4f7f\u7528 Store \u4e2d\u7684\u6210\u5458<\/p>\n<pre>#&nbsp;\u9875\u9762\u7684&nbsp;.wxml\n&lt;view&gt;{{numA}}&nbsp;+&nbsp;{{numB}}&nbsp;=&nbsp;{{sum}}&lt;\/view&gt;&lt;van-button&gt;numA&nbsp;+&nbsp;1&lt;\/van-button&gt;&lt;van-button&gt;numA&nbsp;-&nbsp;1&lt;\/van-button&gt;&lt;!-- \u6309\u94ae tap \u4e8b\u4ef6\u7684\u5904\u7406\u51fd\u6570 --&gt;\nbtnHandler(e)&nbsp;{\n&nbsp;&nbsp;this.updateNumA(e.target.dataset.step)\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5c06 Store \u4e2d\u7684\u6210\u5458\u7ed1\u5b9a\u5230\u7ec4\u4ef6\u4e2d<\/p>\n<pre>import&nbsp;{&nbsp;storeBindingsBehavior&nbsp;}&nbsp;from&nbsp;'mobx-miniprogram-bindings'\nimport&nbsp;{&nbsp;store&nbsp;}&nbsp;from&nbsp;'.\/store'\nComponent({\n&nbsp;&nbsp;behaviors:&nbsp;[storeBindingsBehavior],\n&nbsp;&nbsp;storeBindings:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;store,\n&nbsp;&nbsp;&nbsp;&nbsp;fields:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;numA:&nbsp;()&nbsp;=&amp;gt;&nbsp;store.numA,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;numB:&nbsp;(store)&nbsp;=&amp;gt;&nbsp;store.numB,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sum:&nbsp;'sum'\n&nbsp;&nbsp;&nbsp;&nbsp;},\n&nbsp;&nbsp;&nbsp;&nbsp;actions:&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;updateNumA:&nbsp;'updateNumA'\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;}\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528 Store \u4e2d\u7684\u6210\u5458<\/p>\n<pre>#&nbsp;\u7ec4\u4ef6\u7684&nbsp;.wxml&nbsp;\u7ed3\u6784\n&lt;view&gt;{{numA}}&nbsp;+&nbsp;{{numB}}&nbsp;=&nbsp;{{sum}}&lt;\/view&gt;&lt;van-button&gt;numA&nbsp;+&nbsp;1&lt;\/van-button&gt;&lt;van-button&gt;numA&nbsp;-&nbsp;1&lt;\/van-button&gt;&lt;!-- \u6309\u94ae tap \u4e8b\u4ef6\u7684\u5904\u7406\u51fd\u6570 --&gt;\nbtnHandler(e)&nbsp;{\n&nbsp;&nbsp;this.updateNumA(e.target.dataset.step)\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u3010\u76f8\u5173\u5b66\u4e60\u63a8\u8350\uff1a\u3011<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u57fa\u7840\u52a0\u5f3a\u603b\u7ed3\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\u4e86\u5173\u4e8e\u7684\u76f8\u5173\u95ee\u9898\uff0c\u5176\u4e2d\u4e3b\u8981\u4ecb\u7ecd\u4e86\u4e00\u4e9b\u57fa\u7840\u5185\u5bb9\uff0c\u5305\u62ec\u4e86\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u3001\u6837\u5f0f\u9694\u79bb\u3001\u6570\u636e\u3001\u65b9\u6cd5\u548c\u5c5e\u6027\u7b49\u7b49\u5185\u5bb9\uff0c\u4e0b\u9762\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u6709\u5e2e\u52a9\u3002 \u3010\u76f8\u5173\u5b66\u4e60\u63a8\u8350\uff1a\u3011 1\u3001\u81ea\u5b9a\u4e49\u7ec4\u4ef6 1.1\u3001\u521b\u5efa\u7ec4\u4ef6 \u5728\u9879\u76ee\u7684\u6839\u76ee\u5f55\u4e2d\uff0c\u9f20\u6807\u53f3\u952e\uff0c\u521b\u5efa components -&gt; test \u6587\u4ef6\u5939 \u65b0\u5efa\u7684 components -&gt; test \u6587\u4ef6\u5939\u4e0a\uff0c\u9f20\u6807\u53f3\u952e\uff0c\u70b9\u51fb\u65b0\u5efa Component \u952e\u5165\u7ec4\u4ef6\u7684\u540d\u79f0\u4e4b\u540e\u56de\u8f66\uff0c\u4f1a\u81ea\u52a8\u751f\u6210\u7ec4\u4ef6\u5bf9\u5e94\u7684 4 \u4e2a\u6587\u4ef6\uff0c\u540e\u7f00\u540d\u5206\u522b\u4e3a .js\u3001.json\u3001.wxml \u548c .wxss 1.2\u3001\u5f15\u7528\u7ec4\u4ef6 \u5c40\u90e8\u5f15\u7528\uff1a\u7ec4\u4ef6\u53ea\u80fd\u5728\u5f53\u524d\u88ab\u5f15\u7528\u7684\u9875\u9762\u5185\u4f7f\u7528 \u5168\u5c40\u5f15\u7528\uff1a\u7ec4\u4ef6\u53ef\u4ee5\u5728\u6bcf\u4e2a\u5c0f\u7a0b\u5e8f\u9875\u9762\u4e2d\u4f7f\u7528 1.3\u3001\u5c40\u90e8\u5f15\u7528\u7ec4\u4ef6 \u5728\u9875\u9762\u7684 .json \u914d\u7f6e\u6587\u4ef6\u4e2d\u5f15\u7528\u7ec4\u4ef6\u7684\u65b9\u5f0f\uff0c\u53eb\u505a\u5c40\u90e8\u5f15\u7528\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a #&nbsp;\u5728\u9875\u9762\u7684&nbsp;.json&nbsp;\u6587\u4ef6\u4e2d\uff0c\u5f15\u5165\u7ec4\u4ef6 { &nbsp;&nbsp;&#8220;usingComponents&#8221;:&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&#8220;my-test&#8221;:&nbsp;&#8220;\/components\/test\/test&#8221; &nbsp;&nbsp;} } #&nbsp;\u5728\u9875\u9762\u7684&nbsp;.wxml&nbsp;\u6587\u4ef6\u4e2d\uff0c\u4f7f\u7528\u7ec4\u4ef6 &lt;my-test&gt;&lt;\/my-test&gt; \u767b\u5f55\u540e\u590d\u5236 1.4\u3001\u5168\u5c40\u5f15\u7528\u7ec4\u4ef6 \u5728 app.json \u5168\u5c40\u914d\u7f6e\u6587\u4ef6\u4e2d\u5f15\u7528\u7ec4\u4ef6\u7684\u65b9\u5f0f\uff0c\u53eb\u505a\u5168\u5c40\u5f15\u7528\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a #&nbsp;\u5728&nbsp;app.json&nbsp;\u6587\u4ef6\u4e2d\uff0c\u5f15\u5165\u7ec4\u4ef6 { &nbsp;&nbsp;&#8220;usingComponents&#8221;:&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&#8220;my-test&#8221;:&nbsp;&#8220;\/components\/test\/test&#8221; &nbsp;&nbsp;} } \u767b\u5f55\u540e\u590d\u5236 1.5\u3001\u5168\u5c40\u5f15\u7528 VS \u5c40\u90e8\u5f15\u7528 \u6839\u636e\u7ec4\u4ef6\u7684\u4f7f\u7528\u9891\u7387\u548c\u8303\u56f4\uff0c\u6765\u9009\u62e9\u5408\u9002\u7684\u5f15\u7528\u65b9\u5f0f\uff1a \u5982\u679c\u67d0\u7ec4\u4ef6\u5728\u591a\u4e2a\u9875\u9762\u4e2d\u7ecf\u5e38\u88ab\u7528\u5230\uff0c\u5efa\u8bae\u8fdb\u884c\u5168\u5c40\u5f15\u7528 \u4f7f\u7528\u67d0\u7ec4\u4ef6\u53ea\u5728\u7279\u5b9a\u7684\u9875\u9762\u4e2d\u88ab\u7528\u5230\uff0c\u5efa\u8bae\u8fdb\u884c\u5c40\u90e8\u5f15\u7528 1.6\u3001\u7ec4\u4ef6\u548c\u9875\u9762\u7684\u533a\u522b [&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-34294","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34294","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=34294"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34294\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=34294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=34294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=34294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}