{"id":32528,"date":"2024-11-25T12:54:02","date_gmt":"2024-11-25T04:54:02","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32528\/"},"modified":"2024-11-25T12:54:02","modified_gmt":"2024-11-25T04:54:02","slug":"%e5%b0%8f%e7%a8%8b%e5%ba%8f%e5%bc%80%e5%8f%91%e4%b9%8b%e9%a1%b5%e9%9d%a2%e4%b8%8a%e6%8b%89%e5%8a%a0%e8%bd%bd%e6%95%b0%e6%8d%ae%ef%bc%88%e9%99%84%e4%bb%a3%e7%a0%81%ef%bc%89","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32528\/","title":{"rendered":"\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u9875\u9762\u4e0a\u62c9\u52a0\u8f7d\u6570\u636e\uff08\u9644\u4ee3\u7801\uff09"},"content":{"rendered":"<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5e26\u6765\u7684\u5185\u5bb9\u662f\u5173\u4e8e\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u9875\u9762\u4e0a\u62c9\u52a0\u8f7d\u6570\u636e\uff08\u9644\u4ee3\u7801\uff09\uff0c\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u6709\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<p>\u9700\u6c42\u662f\u4e0a\u62c9\u52a0\u8f7d\u6570\u636e\uff0c\u5b9e\u9645\u5c31\u662f\u83b7\u53d6\u5206\u9875\u6570\u636e\u3002\u540e\u53f0\u5c31\u662f\u6b63\u5e38\u7684ajax\u8bf7\u6c42\u5206\u9875\u6570\u636e\uff0c\u5c0f\u7a0b\u5e8f\u90e8\u5206\u7a0d\u590d\u6742\u4e9b\uff0c\u67e5\u4e86\u4e00\u4e9b\u8d44\u6599\u5b8c\u6210\u7684\uff0c \u4f46\u662f\u8d44\u6599\u7684\u94fe\u63a5\u627e\u4e0d\u5230\u4e86\uff0c\u4e0d\u80fd\u653e\u4e0a\u4ee5\u4f9b\u53c2\u8003\u4e86\u3002<\/p>\n<p><strong>\u5c0f\u7a0b\u5e8f\u9875\u9762<\/strong><\/p>\n<p>\u6d89\u53ca\u5230\u6570\u636e\u5faa\u73af\uff0c\u4e0b\u9762\u662f\u7b80\u5355\u7684\u5b9e\u4f8b<\/p>\n<pre> &lt;view wx:for=\"{{array}}\"&gt;\n     &lt;view &gt;{{item.name}}&lt;\/view&gt;\n     &lt;view &gt;{{item.age}}&lt;\/view&gt;\n  &lt;\/view&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236  MVVM \u7684\u5f00\u53d1\u6a21\u5f0f(\u4f8b\u5982 React, Vue)\uff0c\u63d0\u5021\u628a\u6e32\u67d3\u548c\u903b\u8f91\u5206\u79bb\u3002\u7b80\u5355\u6765\u8bf4\u5c31\u662f\u4e0d\u8981\u518d\u8ba9 JS \u76f4\u63a5\u64cd\u63a7 DOM\uff0cJS\u53ea\u9700\u8981\u7ba1\u7406\u72b6\u6001\u5373\u53ef\uff0c\u7136\u540e\u518d\u901a\u8fc7\u4e00\u79cd\u6a21\u677f\u8bed\u6cd5\u6765\u63cf\u8ff0\u72b6\u6001\u548c\u754c\u9762\u7ed3\u6784\u7684\u5173\u7cfb\u5373\u53ef\u3002 <\/p>\n<p><strong>\u5c0f\u7a0b\u5e8fJS\u90e8\u5206<\/strong><\/p>\n<p>JS\u90e8\u5206\u8d1f\u8d23\u7684\u662f\u83b7\u53d6\u6570\u636e\uff0c\u4ee5\u53ca\u62fc\u63a5\u6570\u636e<\/p>\n<pre>Page({\n\n    \/**\n     * \u9875\u9762\u7684\u521d\u59cb\u6570\u636e\n     *\/\n    data: {\n        array: [],\n        page: 1,\n        isReachBottom: true \/\/ \u662f\u5426\u4e0a\u62c9\u52a0\u8f7d\n    },\n\n    \/\/ \u83b7\u53d6\u6570\u636e\n    getList: function () {\n        var that = this;\n        wx.request({\n            url: 'https:\/\/xxx',\n            data: {\n                p: that.data.page\n            },\n            success: function (res) {\n                if (res.data.message == 'success') {\n                    \/\/ \u83b7\u53d6\u6210\u529f\uff0c\u6570\u636e\u8ffd\u52a0\n                    var list = [];\n                    var count = res.data.data.length\n                    for (var i = 0; i &lt; count; i++) {\n                        var data = {name: '', age: ''};\n                        data.name = res.data.data[i].name;\n                        data.age = res.data.data[i].age;\n                        list.push(data);\n                    }\n                    Array.prototype.push.apply(that.data.array, list);\n                    that.setData({\n                        array: that.data.array\n                    })\n                } else if (res.data.message == 'finish') {\n                    \/\/ \u6ca1\u6709\u6570\u636e\uff0c\u7981\u6b62\u518d\u6b21\u4e0a\u62c9\u52a0\u8f7d\n                    that.setData({\n                        isReachBottom: false\n                    })\n                }\n            }\n        })\n    },\n\n    \/**\n     * \u9875\u9762\u4e0a\u62c9\u89e6\u5e95\u4e8b\u4ef6\u7684\u5904\u7406\u51fd\u6570\n     *\/\n    onReachBottom: function () {\n        if (this.data.isReachBottom == true) {\n            this.setData({\n                page: this.data.page + 1\n            })\n            this.getList()\n        }\n    }\n\n})<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5173\u4e8e\u4e0a\u62c9\u89e6\u5e95\uff0c\u8fd8\u6709\u8fd9\u4e9b\u7279\u6027<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/374\/797\/427\/1548211796238512.png\" class=\"aligncenter\" title=\"\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u9875\u9762\u4e0a\u62c9\u52a0\u8f7d\u6570\u636e\uff08\u9644\u4ee3\u7801\uff09\u63d2\u56fe\" alt=\"\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u9875\u9762\u4e0a\u62c9\u52a0\u8f7d\u6570\u636e\uff08\u9644\u4ee3\u7801\uff09\u63d2\u56fe\" \/><\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u9875\u9762\u4e0a\u62c9\u52a0\u8f7d\u6570\u636e\uff08\u9644\u4ee3\u7801\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>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5e26\u6765\u7684\u5185\u5bb9\u662f\u5173\u4e8e\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u9875\u9762\u4e0a\u62c9\u52a0\u8f7d\u6570\u636e\uff08\u9644\u4ee3\u7801\uff09\uff0c\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u6709\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002 \u9700\u6c42\u662f\u4e0a\u62c9\u52a0\u8f7d\u6570\u636e\uff0c\u5b9e\u9645\u5c31\u662f\u83b7\u53d6\u5206\u9875\u6570\u636e\u3002\u540e\u53f0\u5c31\u662f\u6b63\u5e38\u7684ajax\u8bf7\u6c42\u5206\u9875\u6570\u636e\uff0c\u5c0f\u7a0b\u5e8f\u90e8\u5206\u7a0d\u590d\u6742\u4e9b\uff0c\u67e5\u4e86\u4e00\u4e9b\u8d44\u6599\u5b8c\u6210\u7684\uff0c \u4f46\u662f\u8d44\u6599\u7684\u94fe\u63a5\u627e\u4e0d\u5230\u4e86\uff0c\u4e0d\u80fd\u653e\u4e0a\u4ee5\u4f9b\u53c2\u8003\u4e86\u3002 \u5c0f\u7a0b\u5e8f\u9875\u9762 \u6d89\u53ca\u5230\u6570\u636e\u5faa\u73af\uff0c\u4e0b\u9762\u662f\u7b80\u5355\u7684\u5b9e\u4f8b &lt;view wx:for=&#8221;{{array}}&#8221;&gt; &lt;view &gt;{{item.name}}&lt;\/view&gt; &lt;view &gt;{{item.age}}&lt;\/view&gt; &lt;\/view&gt; \u767b\u5f55\u540e\u590d\u5236 MVVM \u7684\u5f00\u53d1\u6a21\u5f0f(\u4f8b\u5982 React, Vue)\uff0c\u63d0\u5021\u628a\u6e32\u67d3\u548c\u903b\u8f91\u5206\u79bb\u3002\u7b80\u5355\u6765\u8bf4\u5c31\u662f\u4e0d\u8981\u518d\u8ba9 JS \u76f4\u63a5\u64cd\u63a7 DOM\uff0cJS\u53ea\u9700\u8981\u7ba1\u7406\u72b6\u6001\u5373\u53ef\uff0c\u7136\u540e\u518d\u901a\u8fc7\u4e00\u79cd\u6a21\u677f\u8bed\u6cd5\u6765\u63cf\u8ff0\u72b6\u6001\u548c\u754c\u9762\u7ed3\u6784\u7684\u5173\u7cfb\u5373\u53ef\u3002 \u5c0f\u7a0b\u5e8fJS\u90e8\u5206 JS\u90e8\u5206\u8d1f\u8d23\u7684\u662f\u83b7\u53d6\u6570\u636e\uff0c\u4ee5\u53ca\u62fc\u63a5\u6570\u636e Page({ \/** * \u9875\u9762\u7684\u521d\u59cb\u6570\u636e *\/ data: { array: [], page: 1, isReachBottom: true \/\/ \u662f\u5426\u4e0a\u62c9\u52a0\u8f7d }, \/\/ \u83b7\u53d6\u6570\u636e getList: function () { var that = this; wx.request({ url: &#8216;https:\/\/xxx&#8217;, data: { p: that.data.page [&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-32528","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32528","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=32528"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32528\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}