{"id":2703,"date":"2020-04-15T11:38:06","date_gmt":"2020-04-15T03:38:06","guid":{"rendered":"http:\/\/www.yuguoxy.com\/geekhome\/?p=2703"},"modified":"2026-08-18T12:35:28","modified_gmt":"2026-08-18T04:35:28","slug":"vue%e6%a0%b8%e5%bf%83%e4%b9%8b%e8%99%9a%e6%8b%9fdomvdom","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=2703","title":{"rendered":"vue\u6838\u5fc3\u4e4b\u865a\u62dfDOM(vdom)"},"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;\">\u6d4f\u89c8\u5668\u753b\u4e00\u9875\uff0c\u8981\u5148\u6709\u771f\u5b9e DOM\uff0c\u518d\u7b97\u6837\u5f0f\u3001\u5e03\u5c40\u3001\u7ed8\u5236\u3002\u7528 JS \u9891\u7e41\u6539\u8fd9\u4e9b\u8282\u70b9\u4ee3\u4ef7\u5f88\u9ad8\uff1a\u6bcf\u6b21\u6539\u90fd\u53ef\u80fd\u8ba9\u5f15\u64ce\u628a\u6d41\u7a0b\u518d\u8d70\u4e00\u904d\u3002<strong style=\"color: #4870ac;\">\u865a\u62df DOM<\/strong>\uff08vdom\uff09\u7528 JS \u5bf9\u8c61\u5148\u5728\u5185\u5b58\u91cc\u63cf\u8ff0\u754c\u9762\uff0c\u6279\u91cf\u7b97\u51fa\u5dee\u5f02\u518d\u4e00\u6b21\u6027\u8d34\u56de\u771f\u5b9e DOM\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u5b83\u4e0d\u662f\u300c\u4ece\u6b64\u4e0d\u7528\u64cd\u4f5c DOM\u300d\uff0c\u800c\u662f\u628a\u591a\u6b21\u771f\u5b9e DOM \u66f4\u65b0\u6536\u6210\u4e00\u6b21\uff1b\u771f\u6b63\u8ba9 MVVM \u7075\u6d3b\u8d77\u6765\u7684\uff0c\u8fd8\u5305\u62ec\u8de8\u5e73\u53f0\u548c\u670d\u52a1\u7aef\u6e32\u67d3\u3002Diff \u628a\u6bd4\u8f83\u590d\u6742\u5ea6\u4ece O(n\u00b3) \u964d\u5230\u7ea6 O(n)\uff0c\u9760\u7684\u662f\u53ea\u505a\u540c\u5c42\u6bd4\u8f83\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;\">Diff \u7c7b\u578b<\/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;\">\u542b\u4e49<\/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;\">REPLACE<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u8282\u70b9\u7c7b\u578b\u53d8\u4e86\uff0c\u5378\u8f7d\u65e7\u8282\u70b9\uff08\u542b\u5b50\u6811\uff09\u518d\u88c5\u65b0\u7684<\/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;\">PROPS<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u7c7b\u578b\u76f8\u540c\uff0c\u53ea\u6539\u5c5e\u6027\uff0c\u505a\u66f4\u65b0\u800c\u4e0d\u662f\u5378\u8f7d<\/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;\">TEXT<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6587\u672c\u8282\u70b9\u5185\u5bb9\u53d8\u5316<\/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;\">REORDER<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5b50\u8282\u70b9\u79fb\u52a8 \/ \u589e\u52a0 \/ \u5220\u9664\uff0c\u6709 key \u624d\u80fd\u9ad8\u6548\u5b9a\u4f4d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\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\u771f\u5b9e DOM \u548c\u5b83\u7684\u89e3\u6790\u6d41\u7a0b<\/h2>\n<p style=\"margin: 1em 0px;\">\u6e32\u67d3\u5f15\u64ce\u5de5\u4f5c\u6d41\u7a0b\u5927\u81f4\u4e94\u6b65\uff1a\u521b\u5efa DOM \u6811 \u2192 \u521b\u5efa StyleRules \u2192 \u521b\u5efa Render \u6811 \u2192 \u5e03\u5c40 Layout \u2192 \u7ed8\u5236 Painting\u3002<\/p>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>HTML \u5206\u6790\u5668\u5206\u6790\u5143\u7d20\uff0c\u6784\u5efa DOM \u6811\uff08\u6807\u8bb0\u5316\u4e0e\u6811\u6784\u5efa\uff09<\/section>\n<\/li>\n<li>\n<section>CSS \u5206\u6790\u5668\u5206\u6790 CSS \u6587\u4ef6\u548c inline \u6837\u5f0f\uff0c\u751f\u6210\u6837\u5f0f\u8868<\/section>\n<\/li>\n<li>\n<section>DOM \u6811\u548c\u6837\u5f0f\u8868\u5173\u8054\uff0c\u6784\u5efa Render \u6811\uff08Attachment\uff09\u3002\u6bcf\u4e2a DOM \u8282\u70b9\u7684 attach \u63a5\u53d7\u6837\u5f0f\uff0c\u8fd4\u56de renderer\uff0c\u6700\u7ec8\u8fde\u6210 Render \u6811<\/section>\n<\/li>\n<li>\n<section>\u4e3a\u6bcf\u4e2a Render \u8282\u70b9\u786e\u5b9a\u5c4f\u5e55\u4e0a\u7684\u7cbe\u786e\u5750\u6807<\/section>\n<\/li>\n<li>\n<section>\u8c03\u7528\u5404\u8282\u70b9 paint \u65b9\u6cd5\u7ed8\u5236\u51fa\u6765<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\">DOM \u6811\u4e0d\u662f\u7b49\u6587\u6863\u5168\u90e8\u52a0\u8f7d\u5b8c\u624d\u5f00\u59cb\u3002\u4e3a\u4e86\u5c3d\u5feb\u4e0a\u5c4f\uff0c\u4e0d\u5fc5\u7b49\u6574\u4e2a HTML \u89e3\u6790\u5b8c\u624d\u5efa Render \u6811\u548c\u5e03\u5c40\u3002Render \u6811\u4e5f\u4e0d\u662f\u7b49 DOM \u548c CSSOM \u90fd\u5b8c\u6210\u624d\u5f00\u5de5\uff0c\u4e09\u4e2a\u8fc7\u7a0b\u4f1a\u4ea4\u53c9\uff1a\u4e00\u8fb9\u52a0\u8f7d\u3001\u4e00\u8fb9\u89e3\u6790\u3001\u4e00\u8fb9\u6e32\u67d3\u3002<\/p>\n<p style=\"margin: 1em 0px;\">CSS \u4ece\u53f3\u5f80\u5de6\u89e3\u6790\uff08\u4ece DOM \u6811\u81ea\u4e0b\u800c\u4e0a\u901a\u5e38\u66f4\u9ad8\u6548\uff09\uff0c\u5d4c\u5957\u8d8a\u6df1\u8d8a\u6162\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415113248.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2705\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415113248.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415113248\" width=\"634\" height=\"314\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\">\u4e0a\u56fe\u662f WebKit \u6e32\u67d3\u5f15\u64ce\u5de5\u4f5c\u6d41\u7a0b\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;\">\u4e8c\u3001JS \u64cd\u4f5c\u771f\u5b9e DOM \u7684\u4ee3\u4ef7<\/h2>\n<p style=\"margin: 1em 0px;\">\u4f20\u7edf\u7528\u539f\u751f JS \u6216 jQuery \u6539 DOM \u65f6\uff0c\u6d4f\u89c8\u5668\u5f80\u5f80\u4ece\u6784\u5efa DOM \u6811\u5f00\u59cb\u628a\u6d41\u7a0b\u518d\u8dd1\u4e00\u904d\u3002\u4e00\u6b21\u64cd\u4f5c\u8981\u66f4\u65b0 10 \u4e2a\u8282\u70b9\uff0c\u5f15\u64ce\u6536\u5230\u7b2c\u4e00\u4e2a\u8bf7\u6c42\u65f6\u4e0d\u77e5\u9053\u540e\u9762\u8fd8\u6709 9 \u6b21\uff0c\u4e8e\u662f\u9a6c\u4e0a\u6267\u884c\uff0c\u6700\u7ec8\u8dd1 10 \u6b21\u3002\u7b2c\u4e00\u6b21\u7b97\u5b8c\u5750\u6807\uff0c\u4e0b\u4e00\u6b21\u66f4\u65b0\u53c8\u628a\u5750\u6807\u6539\u6389\uff0c\u524d\u9762\u7684\u8ba1\u7b97\u4f5c\u5e9f\u3002\u786c\u4ef6\u5728\u8fed\u4ee3\uff0c\u64cd\u4f5c DOM \u4ecd\u7136\u8d35\uff0c\u9891\u7e41\u6539\u5c31\u4f1a\u5361\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;\">\u4e09\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u865a\u62df DOM<\/h2>\n<p style=\"margin: 1em 0px;\">\u754c\u9762\u7531 DOM \u6811\u6784\u6210\uff0c\u5c40\u90e8\u53d8\u5316\u5bf9\u5e94\u67d0\u4e2a\u8282\u70b9\u53d8\u5316\u3002\u865a\u62df DOM \u5c31\u662f\u4e3a\u6d4f\u89c8\u5668\u6027\u80fd\u8bbe\u8ba1\u7684\uff1a10 \u6b21\u66f4\u65b0\u4e0d\u4f1a\u7acb\u523b\u64cd\u4f5c DOM\uff0c\u800c\u662f\u628a diff \u5148\u5b58\u8fdb\u4e00\u4e2a JS \u5bf9\u8c61\uff0c\u6700\u540e\u4e00\u6b21\u6027 attach \u5230 DOM \u6811\u4e0a\uff0c\u907f\u514d\u5927\u91cf\u65e0\u8c13\u8ba1\u7b97\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u7528 JS \u5bf9\u8c61\u6a21\u62df\u8282\u70b9\u7684\u597d\u5904\uff1a\u66f4\u65b0\u5148\u5168\u90e8\u53cd\u6620\u5728\u5185\u5b58\u91cc\u7684\u865a\u62df DOM \u4e0a\uff0c\u7b49\u5b8c\u6210\u540e\u518d\u6620\u5c04\u6210\u771f\u5b9e DOM \u4ea4\u7ed9\u6d4f\u89c8\u5668\u7ed8\u5236\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\u3001\u7528 JS \u5bf9\u8c61\u5b9e\u73b0\u865a\u62df DOM<\/h2>\n<p style=\"margin: 1em 0px;\">\u4f8b\u5982\u4e00\u4e2a\u771f\u5b9e DOM \u8282\u70b9\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415113316.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2706\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415113316.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415113316\" width=\"606\" height=\"180\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\">\u7528 JS \u6a21\u62df\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415113335.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2707\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415113335.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415113335\" width=\"575\" height=\"234\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\">Element \u65b9\u6cd5\u600e\u4e48\u5b9e\u73b0\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415113552.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2708\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415113552.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415113552\" width=\"592\" height=\"359\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\">\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u8282\u70b9\u540d\uff08\u5982 div\uff09\uff0c\u7b2c\u4e8c\u4e2a\u662f\u5c5e\u6027\uff08\u5982 class\uff09\uff0c\u7b2c\u4e09\u4e2a\u662f\u5b50\u8282\u70b9\uff08\u5982 ul \u91cc\u7684 li\uff09\u3002\u5bf9\u8c61\u4e0a\u8fd8\u4f1a\u4fdd\u5b58 key \u548c count\uff0c\u76f8\u5f53\u4e8e\u4e00\u68f5\u865a\u62df DOM \u6811\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415113614.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2709\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415113614.png\" alt=\"\u256c\u0432\u2568\u253c\u255c\u256a\u2550\u255d_20200415113614\" width=\"704\" height=\"572\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\">\u6709\u4e86 JS \u5bf9\u8c61\uff0c\u8fd8\u8981\u6620\u5c04\u6210\u771f\u5b9e DOM\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" src=\"https:\/\/\/\/upload-images.jianshu.io\/upload_images\/4345378-a7d98ba2e9fb1bdc.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/616\/format\/webp\" alt=\"img\" \/><\/p>\n<p style=\"margin: 1em 0px;\">\u4e4b\u540e\u6240\u6709\u66f4\u65b0\u90fd\u53ef\u4ee5\u5148\u53cd\u6620\u5230\u865a\u62df DOM \u4e0a\u3002\u600e\u4e48\u53cd\u6620\uff1fDiff\u3002\u4e24\u68f5\u6811\u5b8c\u5168\u6bd4\u8f83\u662f O(n\u00b3)\uff1b\u300a\u6df1\u5165\u6d45\u51fa React \u548c Redux\u300b\u91cc\u4ecb\u7ecd React Diff \u662f O(n)\uff0c\u610f\u5473\u7740\u53ea\u80fd\u5e73\u5c42\u6bd4\u8f83\uff0c\u653e\u5f03\u6df1\u5ea6\u8de8\u5c42\u3002\u524d\u7aef\u5f88\u5c11\u8de8\u5c42\u79fb\u52a8 DOM\uff0c\u8fd9\u6837\u662f\u503c\u5f97\u7684\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\u3001\u6df1\u5ea6\u4f18\u5148\u904d\u5386\uff0c\u8bb0\u5f55\u5dee\u5f02<\/h2>\n<p style=\"margin: 1em 0px;\">\u5b9e\u9645\u4f1a\u5bf9\u65b0\u65e7\u4e24\u68f5\u6811\u505a\u6df1\u5ea6\u904d\u5386\uff0c\u6bcf\u4e2a\u8282\u70b9\u6709\u6807\u8bb0\uff1b\u904d\u5386\u5230\u4e00\u4e2a\u8282\u70b9\u5c31\u548c\u65b0\u6811\u5bf9\u6bd4\uff0c\u6709\u5dee\u5f02\u8bb0\u5230\u4e00\u4e2a\u5bf9\u8c61\u91cc\u3002\u4e0b\u9762\u7528\u4e00\u68f5\u65b0\u6811\u548c\u65e7\u6811\u6bd4\u8f83\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" src=\"https:\/\/\/\/upload-images.jianshu.io\/upload_images\/4345378-58f905e4f9049b2c.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/621\/format\/webp\" alt=\"img\" \/><\/p>\n<p style=\"margin: 1em 0px;\">old Tree<\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" src=\"https:\/\/\/\/upload-images.jianshu.io\/upload_images\/4345378-e3aeff752058cd96.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/620\/format\/webp\" alt=\"img\" \/><\/p>\n<p style=\"margin: 1em 0px;\">new Tree\u3002\u5e73\u5c42 Diff \u53ea\u6709\u56db\u79cd\u60c5\u51b5\u3002<\/p>\n<p style=\"margin: 1em 0px;\">1\u3001\u8282\u70b9\u7c7b\u578b\u53d8\u4e86\uff0c\u4f8b\u5982 P \u53d8\u6210 H3\uff0c\u79f0\u4e3a REPLACE\uff1a\u5378\u8f7d\u65e7\u8282\u70b9\uff08\u542b\u5b50\u8282\u70b9\uff09\u518d\u88c5\u65b0\u8282\u70b9\u3002\u5373\u4f7f\u5b50\u6811\u5176\u5b9e\u4e00\u6837\uff0c\u4e3a\u4e86\u907f\u514d O(n\u00b3) \u4e5f\u503c\u5f97\u8fd9\u6837\u505a\u3002\u5f00\u53d1\u4e0a\u5e94\u907f\u514d\u8fd0\u884c\u65f6\u628a div \u6539\u6210 p \u8fd9\u7c7b\u65e0\u8c13\u7684\u7c7b\u578b\u53d8\u5316\u3002<\/p>\n<p style=\"margin: 1em 0px;\">2\u3001\u7c7b\u578b\u4e00\u6837\uff0c\u53ea\u662f\u5c5e\u6027\u6216\u5c5e\u6027\u503c\u53d8\u4e86\uff0c\u79f0\u4e3a PROPS\uff1a\u505a\u66f4\u65b0\uff0c\u4e0d\u5378\u8f7d\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" src=\"https:\/\/\/\/upload-images.jianshu.io\/upload_images\/4345378-6b717c34619c54b2.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/620\/format\/webp\" alt=\"img\" \/><\/p>\n<p style=\"margin: 1em 0px;\">\u67e5\u627e\u4e0d\u540c\u5c5e\u6027\u7684\u65b9\u6cd5\u3002<\/p>\n<p style=\"margin: 1em 0px;\">3\u3001\u6587\u672c\u53d8\u4e86\uff0c\u6587\u672c\u4e5f\u662f Text Node\uff0c\u76f4\u63a5\u6539\u5185\u5bb9\uff0c\u79f0\u4e3a TEXT\u3002<\/p>\n<p style=\"margin: 1em 0px;\">4\u3001\u79fb\u52a8 \/ \u589e\u52a0 \/ \u5220\u9664\u5b50\u8282\u70b9\uff0c\u79f0\u4e3a REORDER\u3002\u4f8b\u5982 A\u3001B\u3001C\u3001D\u3001E \u91cc\u5728 B \u548c C \u4e4b\u95f4\u63d2\u5165 F\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" src=\"https:\/\/\/\/upload-images.jianshu.io\/upload_images\/4345378-4515ca8e797224a0.jpeg?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/700\/format\/webp\" alt=\"img\" \/><\/p>\n<p style=\"margin: 1em 0px;\">\u7b80\u5355\u7c97\u66b4\u7684\u505a\u6cd5\u662f\u904d\u5386\u65b0\u6811\u6bcf\u4e2a\u8282\u70b9\uff0c\u548c\u65e7\u6811\u6bd4\uff0c\u4e0d\u540c\u5c31\u5378\u65e7\u88c5\u65b0\u3002F \u540e\u9762\u6bcf\u4e2a\u8282\u70b9\u90fd\u4f1a\u88ab\u6298\u817e\u4e00\u904d\uff1a\u5378 C \u88c5 F\u3001\u5378 D \u88c5 C\u2026\u2026\u6548\u7387\u5f88\u4f4e\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" src=\"https:\/\/\/\/upload-images.jianshu.io\/upload_images\/4345378-eb3f73c67d3ef57e.jpeg?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/700\/format\/webp\" alt=\"img\" \/><\/p>\n<p style=\"margin: 1em 0px;\">\u7c97\u66b4\u505a\u6cd5\u3002\u5982\u679c\u5728 JSX \u91cc\u7ed9\u6570\u7ec4\u6216\u679a\u4e3e\u52a0 key\uff0c\u5c31\u80fd\u6309 key \u627e\u5230\u4f4d\u7f6e\u3002\u6700\u5c0f\u7f16\u8f91\u8ddd\u79bb\u53ef\u7528 Levenshtein Distance\uff0cO(M*N)\uff1b\u524d\u7aef\u901a\u5e38\u53ea\u8981\u7b80\u5355\u79fb\u52a8\uff0c\u628a\u7cbe\u786e\u6027\u6362\u901f\u5ea6\uff0c\u964d\u5230 O(max(M,N)) \u5373\u53ef\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" src=\"https:\/\/\/\/upload-images.jianshu.io\/upload_images\/4345378-ec9c6737f4e4f1da.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/622\/format\/webp\" alt=\"img\" \/><\/p>\n<p style=\"margin: 1em 0px;\">\u6700\u7ec8 Diff \u51fa\u6765\u7684\u7ed3\u679c\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;\">\u516d\u3001\u6620\u5c04\u6210\u771f\u5b9e DOM<\/h2>\n<p style=\"margin: 1em 0px;\">\u865a\u62df DOM \u6709\u4e86\uff0cDiff \u6709\u4e86\uff0c\u5c31\u53ef\u4ee5\u628a Diff \u5e94\u7528\u5230\u771f\u5b9e DOM\uff1a\u6df1\u5ea6\u904d\u5386\uff0c\u628a\u5dee\u5f02\u66f4\u65b0\u8fdb\u53bb\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" src=\"https:\/\/\/\/upload-images.jianshu.io\/upload_images\/4345378-73e7e6db57d95032.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/617\/format\/webp\" alt=\"img\" \/><\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" src=\"https:\/\/\/\/upload-images.jianshu.io\/upload_images\/4345378-424038129a2f06f9.png?imageMogr2\/auto-orient\/strip|imageView2\/2\/w\/617\/format\/webp\" alt=\"img\" \/><\/p>\n<p style=\"margin: 1em 0px;\">\u4f1a\u6709\u4e24\u4efd\u865a\u62df DOM\uff08new\/old\uff09\u3002\u7528\u6237\u64cd\u4f5c\u6539\u7684\u662f new\uff1bold \u6620\u5c04\u6210\u5b9e\u9645 DOM\uff0c\u7ecf DOM fragment \u4ea4\u7ed9\u6d4f\u89c8\u5668\u3002new \u548c old \u505a diff\uff0c\u5f97\u5230\u56db\u79cd\u53d8\u6362\u7684\u7ed3\u679c\u8868\uff0c\u518d\u7ecf fragment \u66f4\u65b0\u5230\u9875\u9762\u3002<\/p>\n<p style=\"margin: 1em 0px;\">vdom \u7684\u610f\u4e49\u4e0d\u53ea\u662f\u300c\u5feb\u4e00\u70b9\u300d\uff0c\u66f4\u662f\u4e3a\u4e86\u8de8\u5e73\u53f0\u3001\u670d\u52a1\u7aef\u6e32\u67d3\uff0c\u4ee5\u53ca\u4e00\u5957\u8fd8\u7b97\u80fd\u7528\u7684\u66f4\u65b0\u7b56\u7565\uff0c\u8ba9 MVVM \u6846\u67b6\u7075\u6d3b\u8d77\u6765\u3002Diff \u53ea\u662f\u8ba9\u6bd4\u8f83\u66ff\u6362\u66f4\u9ad8\u6548\u3002DOM \u6700\u7ec8\u8fd8\u662f\u8981\u6539\uff0c\u53ea\u4e0d\u8fc7\u7528 fragment \u628a\u53d8\u5316\u7b97\u5b8c\u518d\u66f4\u65b0\u4e00\u6b21\u2014\u2014\u8fd9\u5c31\u662f\u6846\u67b6\u7684\u4ef7\u503c\uff1a\u4e1a\u52a1\u4ee3\u7801\u4e0d\u7528\u81ea\u5df1\u628a\u64cd\u4f5c\u585e\u8fdb fragment\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u94fe\u63a5\uff1a<a class=\"url\" href=\"https:\/\/www.jianshu.com\/p\/af0b398602bc\" target=\"_blank\">https:\/\/www.jianshu.com\/p\/af0b398602bc<\/a><\/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\uff1a\u865a\u62df DOM \u5148\u5728 JS \u5bf9\u8c61\u4e0a\u8bb0\u8d26\uff0cDiff \u53ea\u505a\u540c\u5c42\u56db\u79cd\u8865\u4e01\uff0c\u6700\u540e\u7528 fragment \u4e00\u6b21\u6027\u6253\u5230\u771f\u5b9e DOM\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u6d4f\u89c8\u5668\u753b\u4e00\u9875\uff0c\u8981\u5148\u6709\u771f\u5b9e DOM\uff0c\u518d\u7b97\u6837\u5f0f\u3001\u5e03\u5c40\u3001\u7ed8\u5236\u3002\u7528 JS \u9891\u7e41\u6539\u8fd9\u4e9b\u8282\u70b9\u4ee3\u4ef7\u5f88\u9ad8\uff1a\u6bcf\u6b21\u6539\u90fd\u53ef\u80fd\u8ba9\u5f15\u64ce\u628a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[106,105],"tags":[205],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2703"}],"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=2703"}],"version-history":[{"count":2,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2703\/revisions"}],"predecessor-version":[{"id":2710,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2703\/revisions\/2710"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}