{"id":185384,"date":"2023-09-13T08:08:04","date_gmt":"2023-09-13T00:08:04","guid":{"rendered":"http:\/\/www.idc.net\/help\/185384\/"},"modified":"2023-09-13T08:08:04","modified_gmt":"2023-09-13T00:08:04","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91%e5%b0%8f%e7%a8%8b%e5%ba%8f%e6%95%99%e7%a8%8b%ef%bc%9a%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f-%e5%88%9d%e5%a7%8b%e6%b8%b2%e6%9f%93%e7%bc%93%e5%ad%98","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/185384\/","title":{"rendered":"\u540e\u6d6a\u4e91\u5c0f\u7a0b\u5e8f\u6559\u7a0b\uff1a\u5fae\u4fe1\u5c0f\u7a0b\u5e8f \u521d\u59cb\u6e32\u67d3\u7f13\u5b58"},"content":{"rendered":"<h2>\u521d\u59cb\u6e32\u67d3\u7f13\u5b58<\/h2>\n<blockquote><p>\n  \u57fa\u7840\u5e93 2.11.1 \u5f00\u59cb\u652f\u6301\uff0c\u4f4e\u7248\u672c\u9700\u505a \u517c\u5bb9\u5904\u7406\u3002\n<\/p><\/blockquote>\n<h2>\u521d\u59cb\u6e32\u67d3\u7f13\u5b58\u5de5\u4f5c\u539f\u7406<\/h2>\n<p>\u5c0f\u7a0b\u5e8f\u9875\u9762\u7684\u521d\u59cb\u5316\u5206\u4e3a\u4e24\u4e2a\u90e8\u5206\u3002<\/p>\n<ul>\n<li>\u903b\u8f91\u5c42\u521d\u59cb\u5316\uff1a\u8f7d\u5165\u5fc5\u9700\u7684\u5c0f\u7a0b\u5e8f\u4ee3\u7801\u3001\u521d\u59cb\u5316\u9875\u9762 this \u5bf9\u8c61\uff08\u4e5f\u5305\u62ec\u5b83\u6d89\u53ca\u5230\u7684\u6240\u6709\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684 this \u5bf9\u8c61\uff09\u3001\u5c06\u76f8\u5173\u6570\u636e\u53d1\u9001\u7ed9\u89c6\u56fe\u5c42\u3002<\/li>\n<li>\u89c6\u56fe\u5c42\u521d\u59cb\u5316\uff1a\u8f7d\u5165\u5fc5\u9700\u7684\u5c0f\u7a0b\u5e8f\u4ee3\u7801\uff0c\u7136\u540e\u7b49\u5f85\u903b\u8f91\u5c42\u521d\u59cb\u5316\u5b8c\u6bd5\u5e76\u63a5\u6536\u903b\u8f91\u5c42\u53d1\u9001\u7684\u6570\u636e\uff0c\u6700\u540e\u6e32\u67d3\u9875\u9762\u3002<\/li>\n<\/ul>\n<p>\u5728\u542f\u52a8\u9875\u9762\u65f6\uff0c\u5c24\u5176\u662f\u5c0f\u7a0b\u5e8f\u51b7\u542f\u52a8\u3001\u8fdb\u5165\u7b2c\u4e00\u4e2a\u9875\u9762\u65f6\uff0c\u903b\u8f91\u5c42\u521d\u59cb\u5316\u7684\u65f6\u95f4\u8f83\u957f\u3002\u5728\u9875\u9762\u521d\u59cb\u5316\u8fc7\u7a0b\u4e2d\uff0c\u7528\u6237\u5c06\u770b\u5230\u5c0f\u7a0b\u5e8f\u7684\u6807\u51c6\u8f7d\u5165\u753b\u9762\uff08\u51b7\u542f\u52a8\u65f6\uff09\u6216\u53ef\u80fd\u770b\u5230\u8f7b\u5fae\u7684\u767d\u5c4f\u73b0\u8c61\uff08\u9875\u9762\u8df3\u8f6c\u8fc7\u7a0b\u4e2d\uff09\u3002<\/p>\n<p>\u542f\u7528\u521d\u59cb\u6e32\u67d3\u7f13\u5b58\uff0c\u53ef\u4ee5\u4f7f\u89c6\u56fe\u5c42\u4e0d\u9700\u8981\u7b49\u5f85\u903b\u8f91\u5c42\u521d\u59cb\u5316\u5b8c\u6bd5\uff0c\u800c\u76f4\u63a5\u63d0\u524d\u5c06\u9875\u9762\u521d\u59cb data \u7684\u6e32\u67d3\u7ed3\u679c\u5c55\u793a\u7ed9\u7528\u6237\uff0c\u8fd9\u53ef\u4ee5\u4f7f\u5f97\u9875\u9762\u5bf9\u7528\u6237\u53ef\u89c1\u7684\u65f6\u95f4\u5927\u5927\u63d0\u524d\u3002\u5b83\u7684\u5de5\u4f5c\u539f\u7406\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u5728\u5c0f\u7a0b\u5e8f\u9875\u9762\u7b2c\u4e00\u6b21\u88ab\u6253\u5f00\u540e\uff0c\u5c06\u9875\u9762\u521d\u59cb\u6570\u636e\u6e32\u67d3\u7ed3\u679c\u8bb0\u5f55\u4e0b\u6765\uff0c\u5199\u5165\u4e00\u4e2a\u6301\u4e45\u5316\u7684\u7f13\u5b58\u533a\u57df\uff08\u7f13\u5b58\u53ef\u957f\u65f6\u95f4\u4fdd\u7559\uff0c\u4f46\u53ef\u80fd\u56e0\u4e3a\u5c0f\u7a0b\u5e8f\u66f4\u65b0\u3001\u57fa\u7840\u5e93\u66f4\u65b0\u3001\u50a8\u5b58\u7a7a\u95f4\u56de\u6536\u7b49\u539f\u56e0\u88ab\u6e05\u9664\uff09\uff1b<\/li>\n<li>\u5728\u8fd9\u4e2a\u9875\u9762\u88ab\u7b2c\u4e8c\u6b21\u6253\u5f00\u65f6\uff0c\u68c0\u67e5\u7f13\u5b58\u4e2d\u662f\u5426\u8fd8\u5b58\u6709\u8fd9\u4e2a\u9875\u9762\u4e0a\u4e00\u6b21\u521d\u59cb\u6570\u636e\u7684\u6e32\u67d3\u7ed3\u679c\uff0c\u5982\u679c\u6709\uff0c\u5c31\u76f4\u63a5\u5c06\u6e32\u67d3\u7ed3\u679c\u5c55\u793a\u51fa\u6765\uff1b<\/li>\n<li>\u5982\u679c\u5c55\u793a\u4e86\u7f13\u5b58\u4e2d\u7684\u6e32\u67d3\u7ed3\u679c\uff0c\u8fd9\u4e2a\u9875\u9762\u6682\u65f6\u8fd8\u4e0d\u80fd\u54cd\u5e94\u7528\u6237\u4e8b\u4ef6\uff0c\u7b49\u5230\u903b\u8f91\u5c42\u521d\u59cb\u5316\u5b8c\u6bd5\u540e\u624d\u80fd\u54cd\u5e94\u7528\u6237\u4e8b\u4ef6\u3002<\/li>\n<\/ul>\n<p>\u5229\u7528\u521d\u59cb\u6e32\u67d3\u7f13\u5b58\uff0c\u53ef\u4ee5\uff1a<\/p>\n<ul>\n<li>\u5feb\u901f\u5c55\u793a\u51fa\u9875\u9762\u4e2d\u6c38\u8fdc\u4e0d\u4f1a\u53d8\u7684\u90e8\u5206\uff0c\u5982\u5bfc\u822a\u680f\uff1b<\/li>\n<li>\u9884\u5148\u5c55\u793a\u4e00\u4e2a\u9aa8\u67b6\u9875\uff0c\u63d0\u5347\u7528\u6237\u4f53\u9a8c\uff1b<\/li>\n<li>\u5c55\u793a\u81ea\u5b9a\u4e49\u7684\u52a0\u8f7d\u63d0\u793a\uff1b<\/li>\n<li>\u63d0\u524d\u5c55\u793a\u5e7f\u544a\uff0c\u7b49\u7b49\u3002<\/li>\n<\/ul>\n<h2>\u652f\u6301\u7684\u7ec4\u4ef6<\/h2>\n<p>\u5728\u521d\u59cb\u6e32\u67d3\u7f13\u5b58\u9636\u6bb5\u4e2d\uff0c\u590d\u6742\u7ec4\u4ef6\u4e0d\u80fd\u88ab\u5c55\u793a\u6216\u4e0d\u80fd\u54cd\u5e94\u4ea4\u4e92\u3002<\/p>\n<p>\u76ee\u524d\u652f\u6301\u7684\u5185\u7f6e\u7ec4\u4ef6\uff1a<\/p>\n<ul>\n<li>&lt;view \/&gt;<\/li>\n<li>&lt;text \/&gt;<\/li>\n<li>&lt;button \/&gt;<\/li>\n<li>&lt;image \/&gt;<\/li>\n<li>&lt;scroll-view \/&gt;<\/li>\n<li>&lt;rich-text \/&gt;<\/li>\n<\/ul>\n<p>\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u672c\u8eab\u53ef\u4ee5\u88ab\u5c55\u793a\uff08\u4f46\u5b83\u4eec\u91cc\u9762\u7528\u5230\u7684\u5185\u7f6e\u7ec4\u4ef6\u4e5f\u9075\u5faa\u4e0a\u8ff0\u9650\u5236\uff09\u3002<\/p>\n<h2>\u9759\u6001\u521d\u59cb\u6e32\u67d3\u7f13\u5b58<\/h2>\n<p>\u82e5\u60f3\u542f\u7528\u521d\u59cb\u6e32\u67d3\u7f13\u5b58\uff0c\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u5728\u9875\u9762\u7684&nbsp;json&nbsp;\u6587\u4ef6\u4e2d\u6dfb\u52a0\u914d\u7f6e\u9879&nbsp;\"initialRenderingCache\": \"static\"&nbsp;\uff1a<\/p>\n<pre><code>{\n  \"initialRenderingCache\": \"static\"\n}\n<\/code><\/pre>\n<p>\u5982\u679c\u60f3\u8981\u5bf9\u6240\u6709\u9875\u9762\u542f\u7528\uff0c\u53ef\u4ee5\u5728&nbsp;app.json&nbsp;\u7684&nbsp;window&nbsp;\u914d\u7f6e\u6bb5\u4e2d\u6dfb\u52a0\u8fd9\u4e2a\u914d\u7f6e\uff1a<\/p>\n<pre><code>{\n  \"window\": {\n    \"initialRenderingCache\": \"static\"\n  }\n}\n<\/code><\/pre>\n<p>\u6dfb\u52a0\u8fd9\u4e2a\u914d\u7f6e\u9879\u4e4b\u540e\uff0c\u5728\u624b\u673a\u4e2d\u9884\u89c8\u5c0f\u7a0b\u5e8f\u9996\u9875\uff0c\u7136\u540e\u6740\u6b7b\u5c0f\u7a0b\u5e8f\u518d\u6b21\u8fdb\u5165\uff0c\u5c31\u4f1a\u901a\u8fc7\u521d\u59cb\u6e32\u67d3\u7f13\u5b58\u6765\u6e32\u67d3\u9996\u9875\u3002<\/p>\n<p>\u6ce8\u610f\uff1a\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u521d\u59cb\u6e32\u67d3\u7f13\u5b58\u8bb0\u5f55\u7684\u662f\u9875\u9762 data \u5e94\u7528\u5728\u9875\u9762 WXML \u4e0a\u7684\u7ed3\u679c\uff0c\u4e0d\u5305\u542b\u4efb\u4f55 setData \u7684\u7ed3\u679c\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u60f3\u8981\u5728\u9875\u9762\u4e2d\u5c55\u793a\u51fa\u201c\u6b63\u5728\u52a0\u8f7d\u201d\u51e0\u4e2a\u5b57\uff0c\u8fd9\u51e0\u4e2a\u5b57\u53d7\u5230&nbsp;loading&nbsp;\u6570\u636e\u5b57\u6bb5\u63a7\u5236\uff1a<\/p>\n<pre><code>&lt;view wx:if=\"{{loading}}\"&gt;\u6b63\u5728\u52a0\u8f7d&lt;\/view&gt;\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c&nbsp;loading&nbsp;\u5e94\u5f53\u5728&nbsp;data&nbsp;\u4e2d\u6307\u5b9a\u4e3a&nbsp;true&nbsp;\uff0c\u5982\uff1a<\/p>\n<pre><code>\/\/ \u6b63\u786e\u7684\u505a\u6cd5\nPage({\n  data: {\n    loading: true\n  }\n})\n<\/code><\/pre>\n<p>\u800c\u4e0d\u80fd\u901a\u8fc7&nbsp;setData&nbsp;\u5c06&nbsp;loading&nbsp;\u7f6e\u4e3a&nbsp;true&nbsp;\uff1a<\/p>\n<pre><code>\/\/ \u9519\u8bef\u7684\u505a\u6cd5\uff01\u4e0d\u8981\u8fd9\u4e48\u505a\uff01\nPage({\n  data: {},\n  onLoad: function() {\n    this.setData({\n      loading: true\n    })\n  }\n})\n<\/code><\/pre>\n<p>\u6362\u800c\u8a00\u4e4b\uff0c\u8fd9\u79cd\u505a\u6cd5\u53ea\u5305\u542b\u9875\u9762&nbsp;data&nbsp;\u7684\u6e32\u67d3\u7ed3\u679c\uff0c\u5373\u9875\u9762\u7684\u7eaf\u9759\u6001\u6210\u5206\u3002<\/p>\n<h2>\u5728\u521d\u59cb\u6e32\u67d3\u7f13\u5b58\u4e2d\u6dfb\u52a0\u52a8\u6001\u5185\u5bb9<\/h2>\n<p>\u6709\u4e9b\u573a\u666f\u4e2d\uff0c\u53ea\u662f\u9875\u9762&nbsp;data&nbsp;\u7684\u6e32\u67d3\u7ed3\u679c\u4f1a\u6bd4\u8f83\u5c40\u9650\u3002\u6709\u65f6\u4f1a\u60f3\u8981\u989d\u5916\u5c55\u793a\u4e00\u4e9b\u53ef\u53d8\u7684\u5185\u5bb9\uff0c\u5982\u5c55\u793a\u7684\u5e7f\u544a\u56fe\u7247 URL \u7b49\u3002<\/p>\n<p>\u8fd9\u79cd\u60c5\u51b5\u4e0b\u53ef\u4ee5\u4f7f\u7528\u201c\u52a8\u6001\u201d\u521d\u59cb\u6e32\u67d3\u7f13\u5b58\u7684\u65b9\u5f0f\u3002\u9996\u5148\uff0c\u914d\u7f6e&nbsp;\"initialRenderingCache\": \"dynamic\"&nbsp;\uff1a<\/p>\n<pre><code>{\n  \"initialRenderingCache\": \"dynamic\"\n}\n<\/code><\/pre>\n<p>\u6b64\u65f6\uff0c\u521d\u59cb\u6e32\u67d3\u7f13\u5b58\u4e0d\u4f1a\u88ab\u81ea\u52a8\u542f\u7528\uff0c\u8fd8\u9700\u8981\u5728\u9875\u9762\u4e2d\u8c03\u7528&nbsp;this.setInitialRenderingCache(dynamicData)&nbsp;\u624d\u80fd\u542f\u7528\u3002\u5176\u4e2d\uff0c&nbsp;dynamicData&nbsp;\u662f\u4e00\u7ec4\u6570\u636e\uff0c\u4e0e&nbsp;data&nbsp;\u4e00\u8d77\u53c2\u4e0e\u9875\u9762 WXML \u6e32\u67d3\u3002<\/p>\n<pre><code>Page({\n  data: {\n    loading: true\n  },\n  onReady: function() {\n    this.setInitialRenderingCache({\n      loadingHint: '\u6b63\u5728\u52a0\u8f7d' \/\/ \u8fd9\u4e00\u90e8\u5206\u6570\u636e\u5c06\u88ab\u5e94\u7528\u4e8e\u754c\u9762\u4e0a\uff0c\u76f8\u5f53\u4e8e\u5728\u521d\u59cb data \u57fa\u7840\u4e0a\u989d\u5916\u8fdb\u884c\u4e00\u6b21 setData\n    })\n  }\n})\n<\/code><\/pre>\n<pre><code>&lt;view wx:if=\"{{loading}}\"&gt;{{loadingHint}}&lt;\/view&gt;\n<\/code><\/pre>\n<p>\u4ece\u539f\u7406\u4e0a\u8bf4\uff0c\u5728\u52a8\u6001\u751f\u6210\u521d\u59cb\u6e32\u67d3\u7f13\u5b58\u7684\u65b9\u5f0f\u4e0b\uff0c\u9875\u9762\u4f1a\u5728\u540e\u53f0\u4f7f\u7528\u52a8\u6001\u6570\u636e\u91cd\u65b0\u6e32\u67d3\u4e00\u6b21\uff0c\u56e0\u800c\u5f00\u9500\u76f8\u5bf9\u8f83\u5927\u3002\u56e0\u800c\u8981\u5c3d\u91cf\u907f\u514d\u9891\u7e41\u8c03\u7528&nbsp;this.setInitialRenderingCache&nbsp;\uff0c\u5982\u679c\u5728\u4e00\u4e2a\u9875\u9762\u5185\u591a\u6b21\u8c03\u7528\uff0c\u4ec5\u6700\u540e\u4e00\u6b21\u8c03\u7528\u751f\u6548\u3002<\/p>\n<p>\u6ce8\u610f\uff1a<\/p>\n<ul>\n<li>this.setInitialRenderingCache&nbsp;\u8c03\u7528\u65f6\u673a\u4e0d\u80fd\u65e9\u4e8e&nbsp;Page&nbsp;\u7684&nbsp;onReady&nbsp;\u6216&nbsp;Component&nbsp;\u7684&nbsp;ready&nbsp;\u751f\u547d\u5468\u671f\uff0c\u5426\u5219\u53ef\u80fd\u5bf9\u6027\u80fd\u6709\u8d1f\u9762\u5f71\u54cd\u3002<\/li>\n<li>\u5982\u679c\u60f3\u7981\u7528\u521d\u59cb\u6e32\u67d3\u7f13\u5b58\uff0c\u8c03\u7528&nbsp;this.setInitialRenderingCache(null)&nbsp;\u3002<\/li>\n<\/ul>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u521d\u59cb\u6e32\u67d3\u7f13\u5b58 \u57fa\u7840\u5e93 2.11.1 \u5f00\u59cb\u652f\u6301\uff0c\u4f4e\u7248\u672c\u9700\u505a \u517c\u5bb9\u5904\u7406\u3002 \u521d\u59cb\u6e32\u67d3\u7f13\u5b58\u5de5\u4f5c\u539f\u7406 \u5c0f\u7a0b\u5e8f\u9875\u9762\u7684\u521d\u59cb\u5316 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182398],"tags":[],"class_list":["post-185384","post","type-post","status-publish","format-standard","hentry","category-mini-program"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/185384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=185384"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/185384\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=185384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=185384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=185384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}