{"id":3365,"date":"2022-08-10T15:31:16","date_gmt":"2022-08-10T07:31:16","guid":{"rendered":"http:\/\/www.yuguoxy.com\/geekhome\/?p=3365"},"modified":"2026-08-18T12:35:36","modified_gmt":"2026-08-18T04:35:36","slug":"%e5%a6%82%e6%9e%9c%e5%90%8e%e7%ab%afapi%e4%b8%80%e6%ac%a1%e8%bf%94%e5%9b%9e10%e4%b8%87%e6%9d%a1%e6%95%b0%e6%8d%ae%ef%bc%8c%e5%89%8d%e7%ab%af%e5%ba%94%e8%af%a5%e5%a6%82%e4%bd%95%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=3365","title":{"rendered":"\u5982\u679c\u540e\u7aefAPI\u4e00\u6b21\u8fd4\u56de10\u4e07\u6761\u6570\u636e\uff0c\u524d\u7aef\u5e94\u8be5\u5982\u4f55\u5904\u7406\uff1f"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\">\u9762\u8bd5\u91cc\u5e38\u88ab\u95ee\uff1a\u540e\u7aef API <strong style=\"color: #4870ac;\">\u4e00\u6b21\u8fd4\u56de 10 \u4e07\u6761<\/strong>\uff0c\u524d\u7aef\u600e\u4e48\u5904\u7406\uff1f\u8fd9\u9898\u8003\u7684\u662f\u6e32\u67d3\u6027\u80fd\uff1a\u4e3b\u7ebf\u7a0b\u522b\u5361\u6b7b\u3001\u9996\u5c4f\u522b\u7a7a\u767d 12 \u79d2\u3001\u7528\u6237\u5c4f\u4e0a\u5176\u5b9e\u4e00\u6b21\u4e5f\u770b\u4e0d\u4e86\u90a3\u4e48\u591a\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u4e0b\u9762\u7528 Node \u9020 10 \u4e07\u6761\u6570\u636e\uff0c\u4ece<strong style=\"color: #4870ac;\">\u4e00\u6b21\u6027\u6e32\u67d3<\/strong>\u3001<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">setTimeout<\/code> \u5206\u9875\u3001<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">requestAnimationFrame<\/code>\u3001\u6587\u6863\u7247\u6bb5\uff0c\u5230\u6309\u6eda\u52a8<strong style=\"color: #4870ac;\">\u61d2\u52a0\u8f7d<\/strong>\uff0c\u628a\u51e0\u79cd\u505a\u6cd5\u644a\u5f00\u3002\u82f1\u6587\u539f\u6587\uff1a<a href='https:\/\/medium.com\/frontend-canteen\/if-the-backend-api-returns-100-000-records-at-one-time-how-should-we-handle-it-in-the-frontend-fab21218fe2' target='_blank' class='url'>https:\/\/medium.com\/frontend-canteen\/if-the-backend-api-returns-100-000-records-at-one-time-how-should-we-handle-it-in-the-frontend-fab21218fe2<\/a><\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001\u9020\u4e00\u4e2a 10 \u4e07\u6761\u7684\u63a5\u53e3<\/h2>\n<p style=\"margin: 1em 0px;\">\u5148\u7528 Node \u8d77\u4e00\u4e2a\u4f1a CORS \u7684\u7b80\u5355\u670d\u52a1\uff0c\u65b9\u4fbf\u672c\u5730\u6d4b\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">const http = require('http')\nconst port = 8000;\n\nlet list = []\nlet num = 0\n\n\/\/ create 100,000 records\nfor (let i = 0; i &lt; 100_000; i++) {\n  num++\n  list.push({\n    src: 'https:\/\/miro.medium.com\/fit\/c\/64\/64\/1*XYGoKrb1w5zdWZLOIEevZg.png',\n    text: `hello world ${num}`,\n    tid: num\n  })\n}\n\nhttp.createServer(function (req, res) {\n  \/\/ for Cross-Origin Resource Sharing (CORS)\n  res.writeHead(200, {\n    'Access-Control-Allow-Origin': '*',\n    \"Access-Control-Allow-Methods\": \"DELETE,PUT,POST,GET,OPTIONS\",\n    'Access-Control-Allow-Headers': 'Content-Type'\n  })\n\n  res.end(JSON.stringify(list));\n}).listen(port, function () {\n  console.log('server is listening on port ' + port);\n})<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u542f\u52a8\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">$ node server.js\n# or\n$ nodemon server.js<\/code><\/pre>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001\u524d\u7aef\u9875\u9762\u9aa8\u67b6<\/h2>\n<p style=\"margin: 1em 0px;\">\u4e00\u4e2a HTML \u52a0\u4e00\u4e2a JS\u3002\u5bb9\u5668 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">#container<\/code> \u5360\u6ee1\u89c6\u53e3\u5e76\u5141\u8bb8\u6eda\u52a8\uff0c\u5217\u8868\u9879\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">.sunshine<\/code> \u6a2a\u6392\u56fe\u7247\u548c\u6587\u5b57\u3002<\/p>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">Index.html<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n  &lt;meta charset=\"UTF-8\"&gt;\n  &lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"&gt;\n  &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n  &lt;title&gt;Document&lt;\/title&gt;\n  &lt;style&gt;\n    * {\n      padding: 0;\n      margin: 0;\n    }\n\n    #container {\n      height: 100vh;\n      overflow: auto;\n    }\n\n    .sunshine {\n      display: flex;\n      padding: 10px;\n    }\n\n    img {\n      width: 150px;\n      height: 150px;\n    }\n&lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;div id=\"container\"&gt;\n    &lt;\/div&gt;\n    &lt;script src=\".\/index.js\"&gt;&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">Index.js<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">\/\/ fetch data from the server\nconst getList = () =&gt; {\n  return new Promise((resolve, reject) =&gt; {\n\n    var ajax = new XMLHttpRequest();\n    ajax.open('get', 'http:\/\/127.0.0.1:8000');\n    ajax.send();\n    ajax.onreadystatechange = function () {\n      if (ajax.readyState == 4 &amp;&amp; ajax.status == 200) {\n        resolve(JSON.parse(ajax.responseText))\n      }\n    }\n  })\n}\n\n\/\/ get `container` element\nconst container = document.getElementById('container')\n\n\n\/\/ The rendering logic should be written here.<\/code><\/pre>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e09\u3001\u76f4\u63a5\u6e32\u67d3\uff1a\u4e00\u6b21\u585e\u8fdb DOM<\/h2>\n<p style=\"margin: 1em 0px;\">\u6700\u76f4\u63a5\u7684\u529e\u6cd5\u662f\u62ff\u5230\u5217\u8868\u540e forEach \u5168\u63d2\u8fdb\u53bb\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">const renderList = async () =&gt; {\n    const list = await getList()\n\n    list.forEach(item =&gt; {\n        const div = document.createElement('div')\n        div.className = 'sunshine'\n        div.innerHTML = `&lt;img src=\"${item.src}\" \/&gt;&lt;span&gt;${item.text}&lt;\/span&gt;`\n        container.appendChild(div)\n    })\n}\nrenderList()<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u4e00\u6b21\u6e32\u67d3 100,000 \u6761\u5927\u7ea6\u8981 12 \u79d2\uff0c\u9875\u9762\u957f\u65f6\u95f4\u7a7a\u767d\uff0c\u4e0d\u53ef\u53d6\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u56db\u3001setTimeout \u5206\u9875\u6e32\u67d3<\/h2>\n<p style=\"margin: 1em 0px;\">\u628a\u6570\u636e\u5207\u6210\u6bcf\u9875 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">limit<\/code> \u6761\uff0c\u5171 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">Math.ceil(total\/limit)<\/code> \u9875\uff0c\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">setTimeout(..., 0)<\/code> \u4e00\u9875\u9875\u5f80\u4e0b\u753b\uff0c\u628a\u957f\u4efb\u52a1\u62c6\u5f00\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">const renderList = async () =&gt; {\n\n    const list = await getList()\n\n    const total = list.length\n    const page = 0\n    const limit = 200\n    const totalPage = Math.ceil(total \/ limit)\n\n    const render = (page) =&gt; {\n        if (page &gt;= totalPage) return\n        setTimeout(() =&gt; {\n            for (let i = page * limit; i &lt; page * limit + limit; i++) {\n                const item = list[i]\n                const div = document.createElement('div')\n                div.className = 'sunshine'\n                div.innerHTML = `&lt;img src=\"${item.src}\" \/&gt;&lt;span&gt;${item.text}&lt;\/span&gt;`\n                container.appendChild(div)\n            }\n            render(page + 1)\n        }, 0)\n    }\n    render(page)\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u5206\u9875\u540e\u9996\u5c4f\u80fd\u8f83\u5feb\u51fa\u73b0\u5185\u5bb9\uff0c\u7a7a\u767d\u65f6\u95f4\u53d8\u77ed\u3002\u6ce8\u610f\u5faa\u73af\u91cc\u82e5\u67d0\u9875\u4e0d\u8db3 limit \u6761\uff0c\u5e94\u5bf9 {code(&#8216;item&#8217;)} \u505a\u7a7a\u503c\u5224\u65ad\uff0c\u5426\u5219\u6700\u540e\u4e00\u9875\u4f1a\u62a5\u9519\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e94\u3001requestAnimationFrame + \u6587\u6863\u7247\u6bb5<\/h2>\n<p style=\"margin: 1em 0px;\">\u6e32\u67d3\u8ddf\u5e27\u8d70\u65f6\uff0c\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">requestAnimationFrame<\/code> \u66ff\u6362 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">setTimeout<\/code>\uff0c\u628a\u5de5\u4f5c\u653e\u5230\u4e0b\u4e00\u6b21\u91cd\u7ed8\u524d\uff0c\u51cf\u5c11\u65e0\u6548\u56de\u6d41\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">const renderList = async () =&gt; {\n    const list = await getList()\n\n    const total = list.length\n    const page = 0\n    const limit = 200\n    const totalPage = Math.ceil(total \/ limit)\n\n    const render = (page) =&gt; {\n        if (page &gt;= totalPage) return\n\n        requestAnimationFrame(() =&gt; {\n            for (let i = page * limit; i &lt; page * limit + limit; i++) {\n                const item = list[i]\n                const div = document.createElement('div')\n                div.className = 'sunshine'\n                div.innerHTML = `&lt;img src=\"${item.src}\" \/&gt;&lt;span&gt;${item.text}&lt;\/span&gt;`\n                container.appendChild(div)\n            }\n            render(page + 1)\n        })\n    }\n    render(page)\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">window.requestAnimationFrame()<\/code> \u544a\u8bc9\u6d4f\u89c8\u5668\u4f60\u8981\u505a\u52a8\u753b\uff0c\u5e76\u5728\u4e0b\u4e00\u6b21\u91cd\u7ed8\u524d\u8c03\u7528\u56de\u8c03\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">appendChild<\/code> \u76f4\u63a5\u63d2\u9875\u9762\u5f88\u8d35\u3002\u53ef\u4ee5\u5148\u5efa <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">DocumentFragment<\/code>\uff0c\u8fd9\u4e00\u9875\u7684\u8282\u70b9\u90fd\u6302\u5230\u7247\u6bb5\u4e0a\uff0c\u518d\u4e00\u6b21\u6027\u63d2\u8fdb\u5bb9\u5668\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">const renderList = async () =&gt; {\n    console.time('time')\n    const list = await getList()\n    console.log(list)\n    const total = list.length\n    const page = 0\n    const limit = 200\n    const totalPage = Math.ceil(total \/ limit)\n\n    const render = (page) =&gt; {\n        if (page &gt;= totalPage) return\n        requestAnimationFrame(() =&gt; {\n\n            const fragment = document.createDocumentFragment()\n            for (let i = page * limit; i &lt; page * limit + limit; i++) {\n                const item = list[i]\n                const div = document.createElement('div')\n                div.className = 'sunshine'\n                div.innerHTML = `&lt;img src=\"${item.src}\" \/&gt;&lt;span&gt;${item.text}&lt;\/span&gt;`\n\n                fragment.appendChild(div)\n            }\n            container.appendChild(fragment)\n            render(page + 1)\n        })\n    }\n    render(page)\n    console.timeEnd('time')\n}<\/code><\/pre>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u516d\u3001\u6309\u6eda\u52a8\u61d2\u52a0\u8f7d<\/h2>\n<p style=\"margin: 1em 0px;\">\u5373\u4f7f\u7528\u6237\u4e00\u6b21\u62ff\u5230 10 \u4e07\u6761\uff0c\u5c4f\u5e55\u4e5f\u53ea\u80fd\u540c\u65f6\u663e\u793a\u6709\u9650\u884c\u3002\u53ef\u4ee5\u6309\u6eda\u52a8\u4f4d\u7f6e\u52a8\u6001\u6e32\u67d3\uff1a\u5217\u8868\u672b\u5c3e\u653e\u4e00\u4e2a\u7a7a\u8282\u70b9 blank\uff0cblank \u8fdb\u5165\u89c6\u53e3\u5c31\u518d\u753b\u4e00\u9875\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">getBoundingClientRect<\/code> \u5224\u65ad blank \u662f\u5426\u8d34\u5728\u5bb9\u5668\u5e95\u90e8\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2022\/08\/1660116498097.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2022\/08\/1660116498097.png\" alt=\"1660116498097\" width=\"1001\" height=\"613\" class=\"alignnone size-full wp-image-3367\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\">Vue \u793a\u4f8b\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;script setup lang=\"ts\"&gt;\nimport { onMounted, ref, computed } from 'vue'\nconst getList = () =&gt; {\n  \/\/ code as before\n}\nconst container = ref&lt;HTMLElement&gt;() \/\/ container element\nconst blank = ref&lt;HTMLElement&gt;() \/\/ blank element\nconst list = ref&lt;any&gt;([])\nconst page = ref(1)\nconst limit = 200\nconst maxPage = computed(() =&gt; Math.ceil(list.value.length \/ limit))\n\/\/ List of real presentations\nconst showList = computed(() =&gt; list.value.slice(0, page.value * limit))\nconst handleScroll = () =&gt; {\n  if (page.value &gt; maxPage.value) return\n  const clientHeight = container.value?.clientHeight\n  const blankTop = blank.value?.getBoundingClientRect().top\n  if (clientHeight === blankTop) {\n    \/\/ When the blank node appears in the viewport, the current page number is incremented by 1\n    page.value++\n  }\n}\nonMounted(async () =&gt; {\n  const res = await getList()\n  list.value = res\n})\n&lt;\/script&gt;\n\n&lt;template&gt;\n  &lt;div id=\"container\" @scroll=\"handleScroll\" ref=\"container\"&gt;\n    &lt;div class=\"sunshine\" v-for=\"(item) in showList\" :key=\"item.tid\"&gt;\n      &lt;img :src=\"item.src\" \/&gt;\n      &lt;span&gt;{{ item.text }}&lt;\/span&gt;\n    &lt;\/div&gt;\n    &lt;div ref=\"blank\"&gt;&lt;\/div&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u751f\u4ea7\u91cc\u66f4\u5e38\u89c1\u7684\u662f<strong style=\"color: #4870ac;\">\u865a\u62df\u5217\u8868<\/strong>\uff1a\u53ea\u6e32\u67d3\u53ef\u89c6\u533a\u52a0\u51cf\u51e0\u884c\u7f13\u51b2\u3002\u4e0a\u9762\u7684\u61d2\u52a0\u8f7d\u4ecd\u4f1a\u628a\u5df2\u7ecf\u6eda\u8fc7\u7684\u8282\u70b9\u7559\u5728 DOM \u91cc\uff0c\u6570\u636e\u6781\u5927\u65f6\u5185\u5b58\u4ecd\u4f1a\u6da8\u3002<\/p>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u65b9\u6848<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u505a\u6cd5<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u6548\u679c<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u6ce8\u610f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u4e00\u6b21\u6e32\u67d3<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">forEach \u5168\u63d2 DOM<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u7ea6 12 \u79d2\u7a7a\u767d<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u4e0d\u53ef\u7528<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">setTimeout<\/code> \u5206\u9875<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6bcf\u9875 200 \u6761\uff0c\u5b8f\u4efb\u52a1\u62c6\u5f00<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u9996\u5c4f\u8f83\u5feb<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u4ecd\u4f1a\u63d2\u6ee1 10 \u4e07\u8282\u70b9<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">rAF<\/code> + Fragment<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u8ddf\u5e27 + \u6279\u91cf\u63d2\u5165<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u56de\u6d41\u66f4\u5c11<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">DOM \u603b\u91cf\u8fd8\u5728<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6eda\u52a8\u61d2\u52a0\u8f7d<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">blank \u8fdb\u89c6\u53e3\u518d slice<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6309\u9700\u589e\u52a0\u8282\u70b9<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5df2\u6eda\u8fc7\u7684\u8282\u70b9\u4e0d\u56de\u6536<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin: 1em 0px;\">\u5de5\u4f5c\u4e2d\u771f\u9047\u5230\u4e00\u6b21\u5410 10 \u4e07\u6761\uff0c\u4f18\u5148\u548c\u540e\u7aef\u6539\u6210\u5206\u9875\u6216\u6d41\u5f0f\u63a5\u53e3\uff1b\u524d\u7aef\u4fa7\u518d\u53e0\u865a\u62df\u5217\u8868\u3002\u9762\u8bd5\u53ef\u4ee5\u628a\u8fd9\u6761\u94fe\u8def\u8bb2\u6e05\u695a\u3002<\/p>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1a10 \u4e07\u6761\u4e0d\u80fd\u4e00\u6b21\u704c\u8fdb DOM\uff1b\u62c6\u4efb\u52a1\u80fd\u6551\u9996\u5c4f\uff0c\u771f\u6b63\u8be5\u505a\u7684\u662f\u6309\u53ef\u89c6\u533a\u6e32\u67d3\uff0c\u5e76\u63a8\u52a8\u63a5\u53e3\u5206\u9875\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u9762\u8bd5\u91cc\u5e38\u88ab\u95ee\uff1a\u540e\u7aef API \u4e00\u6b21\u8fd4\u56de 10 \u4e07\u6761\uff0c\u524d\u7aef\u600e\u4e48\u5904\u7406\uff1f\u8fd9\u9898\u8003\u7684\u662f\u6e32\u67d3\u6027\u80fd\uff1a\u4e3b\u7ebf\u7a0b\u522b\u5361\u6b7b\u3001\u9996\u5c4f\u522b\u7a7a\u767d  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[105,127],"tags":[209],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3365"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3365"}],"version-history":[{"count":2,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3365\/revisions"}],"predecessor-version":[{"id":3368,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3365\/revisions\/3368"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}