{"id":6430,"date":"2022-07-16T22:53:19","date_gmt":"2022-07-16T14:53:19","guid":{"rendered":"http:\/\/123.57.164.21\/?p=6430"},"modified":"2022-07-20T10:43:52","modified_gmt":"2022-07-20T02:43:52","slug":"%e5%89%96%e6%9e%90vue%e5%8e%9f%e7%90%86%e5%ae%9e%e7%8e%b0%e5%8f%8c%e5%90%91%e7%bb%91%e5%ae%9amvvm","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=6430","title":{"rendered":"\u5256\u6790Vue\u539f\u7406&#038;\u5b9e\u73b0\u53cc\u5411\u7ed1\u5b9aMVVM"},"content":{"rendered":"\n<p>\u8f6c\u8f7d\uff1ahttps:\/\/segmentfault.com\/a\/1190000006599500<\/p>\n\n\n\n<p><strong>\u672c\u6587\u80fd\u5e2e\u4f60\u505a\u4ec0\u4e48\uff1f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<ul><li>\u4e86\u89e3vue\u7684\u53cc\u5411\u6570\u636e\u7ed1\u5b9a\u539f\u7406\u4ee5\u53ca\u6838\u5fc3\u4ee3\u7801\u6a21\u5757<\/li><li>\u7f13\u89e3\u597d\u5947\u5fc3\u7684\u540c\u65f6\u4e86\u89e3\u5982\u4f55\u5b9e\u73b0\u53cc\u5411\u7ed1\u5b9a<\/li><li>\u4e3a\u4e86\u4fbf\u4e8e\u8bf4\u660e\u539f\u7406\u4e0e\u5b9e\u73b0\uff0c\u672c\u6587\u76f8\u5173\u4ee3\u7801\u4e3b\u8981\u6458\u81ea<a rel=\"noreferrer noopener\" href=\"https:\/\/link.segmentfault.com\/?enc=iYYhIhUaJqvzFBjEdsg02g%3D%3D.HuQhRp3yyLr5ODL4J3sgOTr8ljdxaA7IidikgiIvNM0%3D\" target=\"_blank\">vue\u6e90\u7801<\/a>, \u5e76\u8fdb\u884c\u4e86\u7b80\u5316\u6539\u9020\uff0c\u76f8\u5bf9\u8f83\u7b80\u964b\uff0c\u5e76\u672a\u8003\u8651\u5230\u6570\u7ec4\u7684\u5904\u7406\u3001\u6570\u636e\u7684\u5faa\u73af\u4f9d\u8d56\u7b49\uff0c\u4e5f\u96be\u514d\u5b58\u5728\u4e00\u4e9b\u95ee\u9898\uff0c\u6b22\u8fce\u5927\u5bb6\u6307\u6b63\u3002\u4e0d\u8fc7\u8fd9\u4e9b\u5e76\u4e0d\u4f1a\u5f71\u54cd\u5927\u5bb6\u7684\u9605\u8bfb\u548c\u7406\u89e3\uff0c\u76f8\u4fe1\u770b\u5b8c\u672c\u6587\u540e\u5bf9\u5927\u5bb6\u5728\u9605\u8bfbvue\u6e90\u7801\u7684\u65f6\u5019\u4f1a\u66f4\u6709\u5e2e\u52a9&lt;<\/li><li>\u672c\u6587\u6240\u6709\u76f8\u5173\u4ee3\u7801\u5747\u5728github\u4e0a\u9762\u53ef\u627e\u5230 <a rel=\"noreferrer noopener\" href=\"https:\/\/link.segmentfault.com\/?enc=1rI%2B9adjuWGr8KmPtuI1HQ%3D%3D.x4ipBV0B1KzvdXZOwi4DR%2FMjS0YV9hDmV%2FcqJXdd3ug%3D\" target=\"_blank\">https:\/\/github.com\/DMQ\/mvvm<\/a><\/li><\/ul>\n\n\n\n<p>\u76f8\u4fe1\u5927\u5bb6\u5bf9mvvm\u53cc\u5411\u7ed1\u5b9a\u5e94\u8be5\u90fd\u4e0d\u964c\u751f\u4e86\uff0c\u4e00\u8a00\u4e0d\u5408\u4e0a\u4ee3\u7801\uff0c\u4e0b\u9762\u5148\u770b\u4e00\u4e2a\u672c\u6587\u6700\u7ec8\u5b9e\u73b0\u7684\u6548\u679c\u5427\uff0c\u548cvue\u4e00\u6837\u7684\u8bed\u6cd5\uff0c\u5982\u679c\u8fd8\u4e0d\u4e86\u89e3\u53cc\u5411\u7ed1\u5b9a\uff0c\u731b\u6233<a rel=\"noreferrer noopener\" href=\"https:\/\/link.segmentfault.com\/?enc=4R7mX3vXaQbBWrMLpdidzQ%3D%3D.%2B2ako85RHCjNpxqdJwef4zOyGsUp8YrzodowiAOpFCwvFyHHlSuK5ROMc9Fzzt1GAAR%2F7ObRR6CHKNYSMCUjdTAobEiN3au26S%2F%2FTTykZOk%3D\" target=\"_blank\">Google<\/a><\/p>\n\n\n\n<p><strong>MVVM\u8bbe\u8ba1\u6a21\u5f0f<\/strong><\/p>\n\n\n\n<p>\u4f17\u6240\u5468\u77e5<code>vue<\/code>\u662f\u4e00\u4e2a<strong>MVVM<\/strong> \u6e10\u8fdb\u5f0f\u6846\u67b6\uff0c<strong>MVVM<\/strong>\u662fvue\u7684\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u5728vue\u6846\u67b6\u4e2d\u6570\u636e\u4f1a\u81ea\u52a8\u9a71\u52a8\u89c6\u56fe\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-204-1024x559.png\" alt=\"\" class=\"wp-image-6533\" width=\"439\" height=\"239\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-204-1024x559.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-204-300x164.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-204-768x419.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-204-830x453.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-204-230x126.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-204-350x191.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-204-480x262.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-204.png 1344w\" sizes=\"(max-width: 439px) 100vw, 439px\" \/><\/figure><\/div>\n\n\n\n<p>View\u662f\u89c6\u56fe\uff0c\u5c31\u662fDOM\uff1b\u5bf9\u5e94\u89c6\u56fe\u4e5f\u5c31\u662fHTML\u90e8\u5206&#8211;\u4ee3\u8868UI\u7ec4\u4ef6\uff0c\u5b83\u8d1f\u8d23\u5c06\u6570\u636e\u6a21\u578b\u8f6c\u5316\u6210UI\u5c55\u73b0\u51fa\u6765\u3002 Model\u662f\u6a21\u578b\uff0c\u5c31\u662fvue\u7ec4\u4ef6\u91cc\u7684data\uff0c\u6216\u8005\u8bf4\u662fvuex\u91cc\u7684\u6570\u636e\uff1b&#8211;\u4ee3\u8868\u6570\u636e\u6a21\u578b\uff0c\u4e5f\u53ef\u4ee5\u5728Model\u4e2d\u5b9a\u4e49\u6570\u636e\u4fee\u6539\u548c\u64cd\u4f5c\u7684\u4e1a\u52a1\u903b\u8f91\u3002 ViewModel&#8211;\u76d1\u542c\u6a21\u578b\u6570\u636e\u4e5f\u5c31\u662fdata\u7684\u7684\u6539\u53d8\u548c\u63a7\u5236\u89c6\u56fe\u884c\u4e3a\u3001\u5904\u7406\u7528\u6237\u4ea4\u4e92\uff0c\u7b80\u5355\u7406\u89e3\u5c31\u662f\u4e00\u4e2a\u540c\u6b65View\u548cModel\u7684\u5bf9\u8c61\uff0c\u8fde\u63a5Model\u548cView\u3002<\/p>\n\n\n\n<p>\u5728MVVM\u67b6\u6784\u4e0b\uff0c<code>View<\/code>\u548c<code>Model<\/code>\u4e4b\u95f4\u5e76\u6ca1\u6709\u76f4\u63a5\u7684\u8054\u7cfb\uff0c\u800c\u662f\u901a\u8fc7<code>ViewMode<\/code>\u8fdb\u884c\u4ea4\u4e92\uff0cModel\u548cViewModel\u4e4b\u95f4\u7684\u4ea4\u4e92\u662f\u53cc\u5411\u7684\uff0c\u56e0\u6b64View\u6570\u636e\u7684\u53d8\u5316\u4f1a\u540c\u6b65\u5230Model\u4e2d\uff0c\u800cModel\u6570\u636e\u7684\u53d8\u5316\u4e5f\u4f1a\u7acb\u5373\u53cd\u5e94\u5230View\u4e0a\u3002<\/p>\n\n\n\n<p><code>ViewModel<\/code>\u901a\u8fc7<strong>\u53cc\u5411\u6570\u636e\u7ed1\u5b9a<\/strong>\u628aView\u5c42\u548cModel\u5c42\u8fde\u63a5\u4e86\u8d77\u6765\uff0c\u800cView\u548cModel\u4e4b\u95f4\u7684\u540c\u6b65\u5de5\u4f5c\u5b8c\u5168\u662f\u81ea\u52a8\u7684\uff0c\u65e0\u9700\u4eba\u4e3a\u5e72\u6d89\uff0c\u56e0\u6b64\u5f00\u53d1\u8005\u53ea\u9700\u5173\u6ce8\u4e1a\u52a1\u903b\u8f91\uff0c\u4e0d\u9700\u8981\u624b\u52a8\u64cd\u4f5cDOM\uff0c\u4e0d\u9700\u8981\u5173\u6ce8\u6570\u636e\u72b6\u6001\u7684\u540c\u6b65\u95ee\u9898\uff0c\u590d\u6742\u7684\u6570\u636e\u72b6\u6001\u7ef4\u62a4\u5b8c\u5168\u7531MVVM\u6765\u7edf\u4e00\u7ba1\u7406\u3002<\/p>\n\n\n\n<p>\u7531\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u5f15\u51favue\u662f\u54cd\u5e94\u5f0f\u7684<\/p>\n\n\n\n<p><strong>\u54cd\u5e94\u5f0f<\/strong><\/p>\n\n\n\n<p>Vue \u7684\u54cd\u5e94\u5f0f\u539f\u7406\u662f\u6838\u5fc3\u662f\u901a\u8fc7 ES5 \u7684\u4fdd\u62a4\u5bf9\u8c61\u7684 <code>Object.defindeProperty<\/code>\u4e2d\u7684\u8bbf\u95ee\u5668\u5c5e\u6027\u4e2d\u7684 <code>get<\/code>\u548c <code>set<\/code>\u65b9\u6cd5\uff0cdata \u4e2d\u58f0\u660e\u7684\u5c5e\u6027\u90fd\u88ab\u6dfb\u52a0\u4e86\u8bbf\u95ee\u5668\u5c5e\u6027\uff0c\u5f53\u8bfb\u53d6 data \u4e2d\u7684\u6570\u636e\u65f6\u81ea\u52a8\u8c03\u7528 get \u65b9\u6cd5\uff0c\u5f53\u4fee\u6539 data \u4e2d\u7684\u6570\u636e\u65f6\uff0c\u81ea\u52a8\u8c03\u7528 set \u65b9\u6cd5\uff0c\u68c0\u6d4b\u5230\u6570\u636e\u7684\u53d8\u5316\uff0c\u4f1a\u901a\u77e5\u89c2\u5bdf\u8005 Wacher\uff0c\u89c2\u5bdf\u8005 Wacher\u81ea\u52a8\u89e6\u53d1\u91cd\u65b0render \u5f53\u524d\u7ec4\u4ef6\uff08\u5b50\u7ec4\u4ef6\u4e0d\u4f1a\u91cd\u65b0\u6e32\u67d3\uff09,\u751f\u6210\u65b0\u7684\u865a\u62df DOM \u6811\uff0cVue \u6846\u67b6\u4f1a\u904d\u5386\u5e76\u5bf9\u6bd4\u65b0\u865a\u62df DOM \u6811\u548c\u65e7\u865a\u62df DOM \u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u5dee\u522b\uff0c\u5e76\u8bb0\u5f55\u4e0b\u6765\uff0c\u6700\u540e\uff0c\u52a0\u8f7d\u64cd\u4f5c\uff0c\u5c06\u6240\u6709\u8bb0\u5f55\u7684\u4e0d\u540c\u70b9\uff0c\u5c40\u90e8\u4fee\u6539\u5230\u771f\u5b9e DOM \u6811\u4e0a\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-205-1024x467.png\" alt=\"\" class=\"wp-image-6535\" width=\"542\" height=\"247\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-205-1024x467.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-205-300x137.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-205-768x350.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-205-830x378.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-205-230x105.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-205-350x160.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-205-480x219.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-205.png 1176w\" sizes=\"(max-width: 542px) 100vw, 542px\" \/><\/figure><\/div>\n\n\n\n<p><strong>&nbsp;\u6838\u5fc3\u5b9e\u73b0\u7c7b:<\/strong><\/p>\n\n\n\n<ul><li>Observer : \u5b83\u7684\u4f5c\u7528\u662f\u7ed9\u5bf9\u8c61\u7684\u5c5e\u6027\u6dfb\u52a0 getter \u548c setter\uff0c\u7528\u4e8e\u4f9d\u8d56\u6536\u96c6\u548c\u6d3e\u53d1\u66f4\u65b0\u3002<\/li><li>Dep : \u7528\u4e8e\u6536\u96c6\u5f53\u524d\u54cd\u5e94\u5f0f\u5bf9\u8c61\u7684\u4f9d\u8d56\u5173\u7cfb,\u6bcf\u4e2a\u54cd\u5e94\u5f0f\u5bf9\u8c61\u5305\u62ec\u5b50\u5bf9\u8c61\u90fd\u62e5\u6709\u4e00\u4e2a Dep \u5b9e\u4f8b\uff08\u91cc\u9762 subs \u662f Watcher \u5b9e\u4f8b\u6570\u7ec4\uff09,\u5f53\u6570\u636e\u6709\u53d8\u66f4\u65f6,\u4f1a\u901a\u8fc7 dep.notify()\u901a\u77e5\u5404\u4e2a watcher\u3002<\/li><li>Watcher : \u89c2\u5bdf\u8005\u5bf9\u8c61 , \u5b9e\u4f8b\u5206\u4e3a\u6e32\u67d3 watcher (render watcher),\u8ba1\u7b97\u5c5e\u6027 watcher (computed watcher),\u4fa6\u542c\u5668 watcher\uff08user watcher\uff09\u4e09\u79cd<\/li><\/ul>\n\n\n\n<p><strong>Watcher \u548c Dep \u7684\u5173\u7cfb:<\/strong><\/p>\n\n\n\n<ul><li>watcher \u4e2d\u5b9e\u4f8b\u5316\u4e86 dep \u5e76\u5411 dep.subs \u4e2d\u6dfb\u52a0\u4e86\u8ba2\u9605\u8005,dep \u901a\u8fc7 notify \u904d\u5386\u4e86 dep.subs \u901a\u77e5\u6bcf\u4e2a watcher \u66f4\u65b0\u3002<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-210-1024x283.png\" alt=\"\" class=\"wp-image-6548\" width=\"658\" height=\"182\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-210-1024x283.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-210-300x83.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-210-768x212.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-210-830x229.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-210-230x64.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-210-350x97.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-210-480x133.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-210.png 1266w\" sizes=\"(max-width: 658px) 100vw, 658px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-211-1024x246.png\" alt=\"\" class=\"wp-image-6549\" width=\"667\" height=\"159\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-211-1024x246.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-211-300x72.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-211-768x184.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-211-830x199.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-211-230x55.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-211-350x84.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-211-480x115.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-211.png 1266w\" sizes=\"(max-width: 667px) 100vw, 667px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-212-1024x140.png\" alt=\"\" class=\"wp-image-6551\" width=\"665\" height=\"90\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-212-1024x140.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-212-300x41.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-212-768x105.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-212-830x113.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-212-230x31.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-212-350x48.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-212-480x66.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-212.png 1274w\" sizes=\"(max-width: 665px) 100vw, 665px\" \/><\/figure><\/div>\n\n\n\n<p><strong>\u53cc\u5411\u7ed1\u5b9a\u7684Demo<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;div id=\"mvvm-app\">\n    &lt;input type=\"text\" v-model=\"word\">\n    &lt;p>{{word}}&lt;\/p>\n    &lt;button v-on:click=\"sayHi\">change model&lt;\/button>\n&lt;\/div>\n\n&lt;script src=\".\/js\/observer.js\">&lt;\/script>\n&lt;script src=\".\/js\/watcher.js\">&lt;\/script>\n&lt;script src=\".\/js\/compile.js\">&lt;\/script>\n&lt;script src=\".\/js\/mvvm.js\">&lt;\/script>\n&lt;script>\n    var vm = new MVVM({\n        el: '#mvvm-app',\n        data: {\n            word: 'Hello World!'\n        },\n        methods: {\n            sayHi: function() {\n                this.word = 'Hi, everybody!';\n            }\n        }\n    });\n&lt;\/script><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"259\" height=\"137\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/07\/18548400-57b310ab653d7-1.webp\" alt=\"\" class=\"wp-image-6433\"\/><\/figure><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u51e0\u79cd\u5b9e\u73b0\u53cc\u5411\u7ed1\u5b9a\u7684\u505a\u6cd5<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u76ee\u524d\u51e0\u79cd\u4e3b\u6d41\u7684mvc(vm)\u6846\u67b6\u90fd\u5b9e\u73b0\u4e86\u5355\u5411\u6570\u636e\u7ed1\u5b9a\uff0c\u800c\u6211\u6240\u7406\u89e3\u7684\u53cc\u5411\u6570\u636e\u7ed1\u5b9a\u65e0\u975e\u5c31\u662f\u5728\u5355\u5411\u7ed1\u5b9a\u7684\u57fa\u7840\u4e0a\u7ed9\u53ef\u8f93\u5165\u5143\u7d20\uff08input\u3001textare\u7b49\uff09\u6dfb\u52a0\u4e86change(input)\u4e8b\u4ef6\uff0c\u6765\u52a8\u6001\u4fee\u6539model\u548c view\uff0c\u5e76\u6ca1\u6709\u591a\u9ad8\u6df1\u3002\u6240\u4ee5\u65e0\u9700\u592a\u8fc7\u4ecb\u6000\u662f\u5b9e\u73b0\u7684\u5355\u5411\u6216\u53cc\u5411\u7ed1\u5b9a\u3002<\/p>\n\n\n\n<p>\u5b9e\u73b0\u6570\u636e\u7ed1\u5b9a\u7684\u505a\u6cd5\u6709\u5927\u81f4\u5982\u4e0b\u51e0\u79cd\uff1a<\/p>\n\n\n\n<ul><li>\u53d1\u5e03\u8005-\u8ba2\u9605\u8005\u6a21\u5f0f\uff08backbone.js\uff09<\/li><li>\u810f\u503c\u68c0\u67e5\uff08angular.js\uff09<\/li><li>\u6570\u636e\u52ab\u6301\uff08vue.js\uff09<\/li><\/ul>\n\n\n\n<p><strong>\u53d1\u5e03\u8005-\u8ba2\u9605\u8005\u6a21\u5f0f:<\/strong> \u4e00\u822c\u901a\u8fc7sub, pub\u7684\u65b9\u5f0f\u5b9e\u73b0\u6570\u636e\u548c\u89c6\u56fe\u7684\u7ed1\u5b9a\u76d1\u542c\uff0c\u66f4\u65b0\u6570\u636e\u65b9\u5f0f\u901a\u5e38\u505a\u6cd5\u662f <code>vm.set('property', value)<\/code>\uff0c\u8fd9\u91cc\u6709\u7bc7\u6587\u7ae0\u8bb2\u7684\u6bd4\u8f83\u8be6\u7ec6\uff0c\u6709\u5174\u8da3\u53ef\u70b9<a rel=\"noreferrer noopener\" href=\"https:\/\/link.segmentfault.com\/?enc=YBnrVcpwNgXXmt1pdBTVAA%3D%3D.QqKAjfoqdh0nV2KTzokO2I2QJV4Grttw8GWBKTc35TydpkKtq0M8ypV1XlCouzwT8dvnLE17k12ZBkI7TonEklt0V2GP79jwSlH1sq8aLm%2F8emb4cKIjGezCxz4DcmtQr8WodlDxO7c1%2FzwzAozTCg%3D%3D\" target=\"_blank\">\u8fd9\u91cc<\/a><\/p>\n\n\n\n<p>\u8fd9\u79cd\u65b9\u5f0f\u73b0\u5728\u6bd5\u7adf\u592alow\u4e86\uff0c\u6211\u4eec\u66f4\u5e0c\u671b\u901a\u8fc7 <code>vm.property = value <\/code>\u8fd9\u79cd\u65b9\u5f0f\u66f4\u65b0\u6570\u636e\uff0c\u540c\u65f6\u81ea\u52a8\u66f4\u65b0\u89c6\u56fe\uff0c\u4e8e\u662f\u6709\u4e86\u4e0b\u9762\u4e24\u79cd\u65b9\u5f0f\u3002<\/p>\n\n\n\n<p><strong>\u810f\u503c\u68c0\u67e5:<\/strong> angular.js \u662f\u901a\u8fc7\u810f\u503c\u68c0\u6d4b\u7684\u65b9\u5f0f\u6bd4\u5bf9\u6570\u636e\u662f\u5426\u6709\u53d8\u66f4\uff0c\u6765\u51b3\u5b9a\u662f\u5426\u66f4\u65b0\u89c6\u56fe\uff0c\u6700\u7b80\u5355\u7684\u65b9\u5f0f\u5c31\u662f\u901a\u8fc7 <code>setInterval()<\/code>\uff0c\u5b9a\u65f6\u8f6e\u8be2\u68c0\u6d4b\u6570\u636e\u53d8\u52a8\uff0c\u5f53\u7136Google\u4e0d\u4f1a\u8fd9\u4e48low\uff0cangular\u53ea\u6709\u5728\u6307\u5b9a\u7684\u4e8b\u4ef6\u89e6\u53d1\u65f6\u8fdb\u5165\u810f\u503c\u68c0\u6d4b\uff0c\u5927\u81f4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul><li>DOM\u4e8b\u4ef6\uff0c\u8b6c\u5982\u7528\u6237\u8f93\u5165\u6587\u672c\uff0c\u70b9\u51fb\u6309\u94ae\u7b49\u3002( ng-click )<\/li><li>XHR\u54cd\u5e94\u4e8b\u4ef6 ( $http )<\/li><li>\u6d4f\u89c8\u5668Location\u53d8\u66f4\u4e8b\u4ef6 ( $location )<\/li><li>Timer\u4e8b\u4ef6( $timeout , $interval )<\/li><li>\u6267\u884c $digest() \u6216 $apply()<\/li><\/ul>\n\n\n\n<p><strong>\u6570\u636e\u52ab\u6301:<\/strong> vue.js \u5219\u662f\u91c7\u7528\u6570\u636e\u52ab\u6301\u7ed3\u5408\u53d1\u5e03\u8005-\u8ba2\u9605\u8005\u6a21\u5f0f\u7684\u65b9\u5f0f\uff0c\u901a\u8fc7<code>Object.defineProperty()<\/code>\u6765\u52ab\u6301\u5404\u4e2a\u5c5e\u6027\u7684<code>setter<\/code>\uff0c<code>getter<\/code>\uff0c\u5728\u6570\u636e\u53d8\u52a8\u65f6\u53d1\u5e03\u6d88\u606f\u7ed9\u8ba2\u9605\u8005\uff0c\u89e6\u53d1\u76f8\u5e94\u7684\u76d1\u542c\u56de\u8c03\u3002<\/p>\n\n\n\n<p><strong>\u601d\u8def\u6574\u7406<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5df2\u7ecf\u4e86\u89e3\u5230vue\u662f\u901a\u8fc7\u6570\u636e\u52ab\u6301\u7684\u65b9\u5f0f\u6765\u505a\u6570\u636e\u7ed1\u5b9a\u7684\uff0c\u5176\u4e2d\u6700\u6838\u5fc3\u7684\u65b9\u6cd5\u4fbf\u662f\u901a\u8fc7<code>Object.defineProperty()<\/code>\u6765\u5b9e\u73b0\u5bf9\u5c5e\u6027\u7684\u52ab\u6301\uff0c\u8fbe\u5230\u76d1\u542c\u6570\u636e\u53d8\u52a8\u7684\u76ee\u7684\uff0c\u65e0\u7591\u8fd9\u4e2a\u65b9\u6cd5\u662f\u672c\u6587\u4e2d\u6700\u91cd\u8981\u3001\u6700\u57fa\u7840\u7684\u5185\u5bb9\u4e4b\u4e00\uff0c\u5982\u679c\u4e0d\u719f\u6089defineProperty\uff0c\u731b\u6233<a rel=\"noreferrer noopener\" href=\"https:\/\/link.segmentfault.com\/?enc=zMnQQgwo8iaNIe1z8j9X0A%3D%3D.Np76sGFl%2B6KgdzxzL3SCxUUGO1fn38cT1EaXmcB99CUlhLBL370xu6wYBo0QOlmFHvZ4ZkYor7Vlxhcg4C9nzCsMXdTjK%2Bss6to7%2BUwH8BlSKR2HWAjKs82Keau1f6qSkitsO%2B%2FkBiLrwO3JemSr3Q%3D%3D\" target=\"_blank\">\u8fd9\u91cc<\/a><\/p>\n\n\n\n<p>\u6574\u7406\u4e86\u4e00\u4e0b\uff0c\u8981\u5b9e\u73b0mvvm\u7684\u53cc\u5411\u7ed1\u5b9a\uff0c\u5c31\u5fc5\u987b\u8981\u5b9e\u73b0\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n\n\n\n<ul><li>1\u3001\u5b9e\u73b0\u4e00\u4e2a\u6570\u636e\u76d1\u542c\u5668Observer\uff0c\u80fd\u591f\u5bf9\u6570\u636e\u5bf9\u8c61\u7684\u6240\u6709\u5c5e\u6027\u8fdb\u884c\u76d1\u542c\uff0c\u5982\u6709\u53d8\u52a8\u53ef\u62ff\u5230\u6700\u65b0\u503c\u5e76\u901a\u77e5\u8ba2\u9605\u8005<\/li><li>2\u3001\u5b9e\u73b0\u4e00\u4e2a\u6307\u4ee4\u89e3\u6790\u5668Compile\uff0c\u5bf9\u6bcf\u4e2a\u5143\u7d20\u8282\u70b9\u7684\u6307\u4ee4\u8fdb\u884c\u626b\u63cf\u548c\u89e3\u6790\uff0c\u6839\u636e\u6307\u4ee4\u6a21\u677f\u66ff\u6362\u6570\u636e\uff0c\u4ee5\u53ca\u7ed1\u5b9a\u76f8\u5e94\u7684\u66f4\u65b0\u51fd\u6570<\/li><li>3\u3001\u5b9e\u73b0\u4e00\u4e2aWatcher\uff0c\u4f5c\u4e3a\u8fde\u63a5Observer\u548cCompile\u7684\u6865\u6881\uff0c\u80fd\u591f\u8ba2\u9605\u5e76\u6536\u5230\u6bcf\u4e2a\u5c5e\u6027\u53d8\u52a8\u7684\u901a\u77e5\uff0c\u6267\u884c\u6307\u4ee4\u7ed1\u5b9a\u7684\u76f8\u5e94\u56de\u8c03\u51fd\u6570\uff0c\u4ece\u800c\u66f4\u65b0\u89c6\u56fe<\/li><li>4\u3001mvvm\u5165\u53e3\u51fd\u6570\uff0c\u6574\u5408\u4ee5\u4e0a\u4e09\u8005<\/li><\/ul>\n\n\n\n<p>\u4e0a\u8ff0\u6d41\u7a0b\u5982\u56fe\u6240\u793a\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-174-1024x544.png\" alt=\"\" class=\"wp-image-6435\" width=\"639\" height=\"339\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-174-1024x544.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-174-300x159.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-174-768x408.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-174-830x441.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-174-230x122.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-174-350x186.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-174-480x255.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-174.png 1468w\" sizes=\"(max-width: 639px) 100vw, 639px\" \/><\/figure><\/div>\n\n\n\n<p><strong>1\u3001\u5b9e\u73b0Observer<\/strong><\/p>\n\n\n\n<p>ok, \u601d\u8def\u5df2\u7ecf\u6574\u7406\u5b8c\u6bd5\uff0c\u4e5f\u5df2\u7ecf\u6bd4\u8f83\u660e\u786e\u76f8\u5173\u903b\u8f91\u548c\u6a21\u5757\u529f\u80fd\u4e86\uff0clet&#8217;s do it<br>\u6211\u4eec\u77e5\u9053\u53ef\u4ee5\u5229\u7528<code>Obeject.defineProperty()<\/code>\u6765\u76d1\u542c\u5c5e\u6027\u53d8\u52a8<br>\u90a3\u4e48\u5c06\u9700\u8981observe\u7684\u6570\u636e\u5bf9\u8c61\u8fdb\u884c\u9012\u5f52\u904d\u5386\uff0c\u5305\u62ec\u5b50\u5c5e\u6027\u5bf9\u8c61\u7684\u5c5e\u6027\uff0c\u90fd\u52a0\u4e0a <code>setter<\/code>\u548c<code>getter<\/code><br>\u8fd9\u6837\u7684\u8bdd\uff0c\u7ed9\u8fd9\u4e2a\u5bf9\u8c61\u7684\u67d0\u4e2a\u503c\u8d4b\u503c\uff0c\u5c31\u4f1a\u89e6\u53d1<code>setter<\/code>\uff0c\u90a3\u4e48\u5c31\u80fd\u76d1\u542c\u5230\u4e86\u6570\u636e\u53d8\u5316\u3002\u3002\u76f8\u5173\u4ee3\u7801\u53ef\u4ee5\u662f\u8fd9\u6837\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">var data = {name: 'kindeng'};\nobserve(data);\ndata.name = 'dmq'; \/\/ \u54c8\u54c8\u54c8\uff0c\u76d1\u542c\u5230\u503c\u53d8\u5316\u4e86 kindeng --> dmq\n\nfunction observe(data) {\n    if (!data || typeof data !== 'object') {\n        return;\n    }\n    \/\/ \u53d6\u51fa\u6240\u6709\u5c5e\u6027\u904d\u5386\n    Object.keys(data).forEach(function(key) {\n        defineReactive(data, key, data[key]);\n    });\n};\n\nfunction defineReactive(data, key, val) {\n    observe(val); \/\/ \u76d1\u542c\u5b50\u5c5e\u6027\n    Object.defineProperty(data, key, {\n        enumerable: true, \/\/ \u53ef\u679a\u4e3e\n        configurable: false, \/\/ \u4e0d\u80fd\u518ddefine\n        get: function() {\n            return val;\n        },\n        set: function(newVal) {\n            console.log('\u54c8\u54c8\u54c8\uff0c\u76d1\u542c\u5230\u503c\u53d8\u5316\u4e86 ', val, ' --> ', newVal);\n            val = newVal;\n        }\n    });\n}\n<\/pre>\n\n\n\n<p>\u8fd9\u6837\u6211\u4eec\u5df2\u7ecf\u53ef\u4ee5\u76d1\u542c\u6bcf\u4e2a\u6570\u636e\u7684\u53d8\u5316\u4e86\uff0c\u90a3\u4e48\u76d1\u542c\u5230\u53d8\u5316\u4e4b\u540e\u5c31\u662f\u600e\u4e48\u901a\u77e5\u8ba2\u9605\u8005\u4e86\uff0c\u6240\u4ee5\u63a5\u4e0b\u6765\u6211\u4eec\u9700\u8981\u5b9e\u73b0\u4e00\u4e2a\u6d88\u606f\u8ba2\u9605\u5668\uff0c\u5f88\u7b80\u5355\uff0c\u7ef4\u62a4\u4e00\u4e2a\u6570\u7ec4\uff0c\u7528\u6765\u6536\u96c6\u8ba2\u9605\u8005\uff0c\u6570\u636e\u53d8\u52a8\u89e6\u53d1notify\uff0c\u518d\u8c03\u7528\u8ba2\u9605\u8005\u7684update\u65b9\u6cd5\uff0c\u4ee3\u7801\u6539\u5584\u4e4b\u540e\u662f\u8fd9\u6837\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ ... \u7701\u7565\nfunction defineReactive(data, key, val) {\n    var dep = new Dep();\n    observe(val); \/\/ \u76d1\u542c\u5b50\u5c5e\u6027\n\n    Object.defineProperty(data, key, {\n        \/\/ ... \u7701\u7565\n        set: function(newVal) {\n            if (val === newVal) return;\n            console.log('\u54c8\u54c8\u54c8\uff0c\u76d1\u542c\u5230\u503c\u53d8\u5316\u4e86 ', val, ' --> ', newVal);\n            val = newVal;\n            dep.notify(); \/\/ \u901a\u77e5\u6240\u6709\u8ba2\u9605\u8005\n        }\n    });\n}\n\nfunction Dep() {\n    this.subs = [];\n}\nDep.prototype = {\n    addSub: function(sub) {\n        this.subs.push(sub);\n    },\n    notify: function() {\n        this.subs.forEach(function(sub) {\n            sub.update();\n        });\n    }\n};<\/pre>\n\n\n\n<p>\u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff0c\u8c01\u662f\u8ba2\u9605\u8005\uff1f\u600e\u4e48\u5f80\u8ba2\u9605\u5668\u6dfb\u52a0\u8ba2\u9605\u8005\uff1f<br>\u6ca1\u9519\uff0c\u4e0a\u9762\u7684\u601d\u8def\u6574\u7406\u4e2d\u6211\u4eec\u5df2\u7ecf\u660e\u786e\u8ba2\u9605\u8005\u5e94\u8be5\u662fWatcher, \u800c\u4e14<code>var dep = new Dep();<\/code>\u662f\u5728 <code>defineReactive<\/code>\u65b9\u6cd5\u5185\u90e8\u5b9a\u4e49\u7684\uff0c\u6240\u4ee5\u60f3\u901a\u8fc7<code>dep<\/code>\u6dfb\u52a0\u8ba2\u9605\u8005\uff0c\u5c31\u5fc5\u987b\u8981\u5728\u95ed\u5305\u5185\u64cd\u4f5c\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u5728 <code>getter<\/code>\u91cc\u9762\u52a8\u624b\u811a\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Observer.js\n\/\/ ...\u7701\u7565\nObject.defineProperty(data, key, {\n    get: function() {\n        \/\/ \u7531\u4e8e\u9700\u8981\u5728\u95ed\u5305\u5185\u6dfb\u52a0watcher\uff0c\u6240\u4ee5\u901a\u8fc7Dep\u5b9a\u4e49\u4e00\u4e2a\u5168\u5c40target\u5c5e\u6027\uff0c\u6682\u5b58watcher, \u6dfb\u52a0\u5b8c\u79fb\u9664\n        Dep.target &amp;&amp; dep.addSub(Dep.target);\n        return val;\n    }\n    \/\/ ... \u7701\u7565\n});\n\n\/\/ Watcher.js\nWatcher.prototype = {\n    get: function(key) {\n        Dep.target = this;\n        this.value = data[key];    \/\/ \u8fd9\u91cc\u4f1a\u89e6\u53d1\u5c5e\u6027\u7684getter\uff0c\u4ece\u800c\u6dfb\u52a0\u8ba2\u9605\u8005\n        Dep.target = null;\n    }\n}<\/pre>\n\n\n\n<p>\u8fd9\u91cc\u5df2\u7ecf\u5b9e\u73b0\u4e86\u4e00\u4e2aObserver\u4e86\uff0c\u5df2\u7ecf\u5177\u5907\u4e86\u76d1\u542c\u6570\u636e\u548c\u6570\u636e\u53d8\u5316\u901a\u77e5\u8ba2\u9605\u8005\u7684\u529f\u80fd\uff0c<a rel=\"noreferrer noopener\" href=\"https:\/\/link.segmentfault.com\/?enc=OXKKpYeliC6961ie4nW1ew%3D%3D.G5GRxhw1f2IOtVS1Q6DVEgYHMbSkR5qXSB%2FSLqfGx4rEaYslbmZVVrlIWSb0wFAjsVO5%2FOqsfGIiPdhEObJCpw%3D%3D\" target=\"_blank\">\u5b8c\u6574\u4ee3\u7801<\/a>\u3002\u90a3\u4e48\u63a5\u4e0b\u6765\u5c31\u662f\u5b9e\u73b0Compile\u4e86<\/p>\n\n\n\n<p><strong>2\u3001\u5b9e\u73b0Compile<\/strong><\/p>\n\n\n\n<p>compile\u4e3b\u8981\u505a\u7684\u4e8b\u60c5\u662f\u89e3\u6790\u6a21\u677f\u6307\u4ee4\uff0c\u5c06\u6a21\u677f\u4e2d\u7684\u53d8\u91cf\u66ff\u6362\u6210\u6570\u636e\uff0c\u7136\u540e\u521d\u59cb\u5316\u6e32\u67d3\u9875\u9762\u89c6\u56fe\uff0c\u5e76\u5c06\u6bcf\u4e2a\u6307\u4ee4\u5bf9\u5e94\u7684\u8282\u70b9\u7ed1\u5b9a\u66f4\u65b0\u51fd\u6570\uff0c\u6dfb\u52a0\u76d1\u542c\u6570\u636e\u7684\u8ba2\u9605\u8005\uff0c\u4e00\u65e6\u6570\u636e\u6709\u53d8\u52a8\uff0c\u6536\u5230\u901a\u77e5\uff0c\u66f4\u65b0\u89c6\u56fe\uff0c\u5982\u56fe\u6240\u793a\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-175-1024x405.png\" alt=\"\" class=\"wp-image-6436\" width=\"554\" height=\"219\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-175-1024x405.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-175-300x119.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-175-768x304.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-175-830x328.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-175-230x91.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-175-350x138.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-175-480x190.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/07\/\u56fe\u7247-175.png 1254w\" sizes=\"(max-width: 554px) 100vw, 554px\" \/><\/figure><\/div>\n\n\n\n<p>\u56e0\u4e3a\u904d\u5386\u89e3\u6790\u7684\u8fc7\u7a0b\u6709\u591a\u6b21\u64cd\u4f5cdom\u8282\u70b9\uff0c\u4e3a\u63d0\u9ad8\u6027\u80fd\u548c\u6548\u7387\uff0c\u4f1a\u5148\u5c06\u8ddf\u8282\u70b9<code>el<\/code>\u8f6c\u6362\u6210\u6587\u6863\u788e\u7247<code>fragment<\/code>\u8fdb\u884c\u89e3\u6790\u7f16\u8bd1\u64cd\u4f5c\uff0c\u89e3\u6790\u5b8c\u6210\uff0c\u518d\u5c06<code>fragment<\/code>\u6dfb\u52a0\u56de\u539f\u6765\u7684\u771f\u5b9edom\u8282\u70b9\u4e2d<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function Compile(el) {\n    this.$el = this.isElementNode(el) ? el : document.querySelector(el);\n    if (this.$el) {\n        this.$fragment = this.node2Fragment(this.$el);\n        this.init();\n        this.$el.appendChild(this.$fragment);\n    }\n}\nCompile.prototype = {\n    init: function() { this.compileElement(this.$fragment); },\n    node2Fragment: function(el) {\n        var fragment = document.createDocumentFragment(), child;\n        \/\/ \u5c06\u539f\u751f\u8282\u70b9\u62f7\u8d1d\u5230fragment\n        while (child = el.firstChild) {\n            fragment.appendChild(child);\n        }\n        return fragment;\n    }\n};<\/pre>\n\n\n\n<p>compileElement\u65b9\u6cd5\u5c06\u904d\u5386\u6240\u6709\u8282\u70b9\u53ca\u5176\u5b50\u8282\u70b9\uff0c\u8fdb\u884c\u626b\u63cf\u89e3\u6790\u7f16\u8bd1\uff0c\u8c03\u7528\u5bf9\u5e94\u7684\u6307\u4ee4\u6e32\u67d3\u51fd\u6570\u8fdb\u884c\u6570\u636e\u6e32\u67d3\uff0c\u5e76\u8c03\u7528\u5bf9\u5e94\u7684\u6307\u4ee4\u66f4\u65b0\u51fd\u6570\u8fdb\u884c\u7ed1\u5b9a\uff0c\u8be6\u770b\u4ee3\u7801\u53ca\u6ce8\u91ca\u8bf4\u660e\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Compile.prototype = {\n    \/\/ ... \u7701\u7565\n    compileElement: function(el) {\n        var childNodes = el.childNodes, me = this;\n        [].slice.call(childNodes).forEach(function(node) {\n            var text = node.textContent;\n            var reg = \/\\{\\{(.*)\\}\\}\/;    \/\/ \u8868\u8fbe\u5f0f\u6587\u672c\n            \/\/ \u6309\u5143\u7d20\u8282\u70b9\u65b9\u5f0f\u7f16\u8bd1\n            if (me.isElementNode(node)) {\n                me.compile(node);\n            } else if (me.isTextNode(node) &amp;&amp; reg.test(text)) {\n                me.compileText(node, RegExp.$1);\n            }\n            \/\/ \u904d\u5386\u7f16\u8bd1\u5b50\u8282\u70b9\n            if (node.childNodes &amp;&amp; node.childNodes.length) {\n                me.compileElement(node);\n            }\n        });\n    },\n\n    compile: function(node) {\n        var nodeAttrs = node.attributes, me = this;\n        [].slice.call(nodeAttrs).forEach(function(attr) {\n            \/\/ \u89c4\u5b9a\uff1a\u6307\u4ee4\u4ee5 v-xxx \u547d\u540d\n            \/\/ \u5982 &lt;span v-text=\"content\">&lt;\/span> \u4e2d\u6307\u4ee4\u4e3a v-text\n            var attrName = attr.name;    \/\/ v-text\n            if (me.isDirective(attrName)) {\n                var exp = attr.value; \/\/ content\n                var dir = attrName.substring(2);    \/\/ text\n                if (me.isEventDirective(dir)) {\n                    \/\/ \u4e8b\u4ef6\u6307\u4ee4, \u5982 v-on:click\n                    compileUtil.eventHandler(node, me.$vm, exp, dir);\n                } else {\n                    \/\/ \u666e\u901a\u6307\u4ee4\n                    compileUtil[dir] &amp;&amp; compileUtil[dir](node, me.$vm, exp);\n                }\n            }\n        });\n    }\n};\n\n\/\/ \u6307\u4ee4\u5904\u7406\u96c6\u5408\nvar compileUtil = {\n    text: function(node, vm, exp) {\n        this.bind(node, vm, exp, 'text');\n    },\n    \/\/ ...\u7701\u7565\n    bind: function(node, vm, exp, dir) {\n        var updaterFn = updater[dir + 'Updater'];\n        \/\/ \u7b2c\u4e00\u6b21\u521d\u59cb\u5316\u89c6\u56fe\n        updaterFn &amp;&amp; updaterFn(node, vm[exp]);\n        \/\/ \u5b9e\u4f8b\u5316\u8ba2\u9605\u8005\uff0c\u6b64\u64cd\u4f5c\u4f1a\u5728\u5bf9\u5e94\u7684\u5c5e\u6027\u6d88\u606f\u8ba2\u9605\u5668\u4e2d\u6dfb\u52a0\u4e86\u8be5\u8ba2\u9605\u8005watcher\n        new Watcher(vm, exp, function(value, oldValue) {\n            \/\/ \u4e00\u65e6\u5c5e\u6027\u503c\u6709\u53d8\u5316\uff0c\u4f1a\u6536\u5230\u901a\u77e5\u6267\u884c\u6b64\u66f4\u65b0\u51fd\u6570\uff0c\u66f4\u65b0\u89c6\u56fe\n            updaterFn &amp;&amp; updaterFn(node, value, oldValue);\n        });\n    }\n};\n\n\/\/ \u66f4\u65b0\u51fd\u6570\nvar updater = {\n    textUpdater: function(node, value) {\n        node.textContent = typeof value == 'undefined' ? '' : value;\n    }\n    \/\/ ...\u7701\u7565\n};<\/pre>\n\n\n\n<p>\u8fd9\u91cc\u901a\u8fc7\u9012\u5f52\u904d\u5386\u4fdd\u8bc1\u4e86\u6bcf\u4e2a\u8282\u70b9\u53ca\u5b50\u8282\u70b9\u90fd\u4f1a\u89e3\u6790\u7f16\u8bd1\u5230\uff0c\u5305\u62ec\u4e86{{}}\u8868\u8fbe\u5f0f\u58f0\u660e\u7684\u6587\u672c\u8282\u70b9\u3002\u6307\u4ee4\u7684\u58f0\u660e\u89c4\u5b9a\u662f\u901a\u8fc7\u7279\u5b9a\u524d\u7f00\u7684\u8282\u70b9\u5c5e\u6027\u6765\u6807\u8bb0\uff0c\u5982<code>&lt;span v-text=\"content\" other-attr<\/code>\u4e2d<code>v-text<\/code>\u4fbf\u662f\u6307\u4ee4\uff0c\u800c<code>other-attr<\/code>\u4e0d\u662f\u6307\u4ee4\uff0c\u53ea\u662f\u666e\u901a\u7684\u5c5e\u6027\u3002<br>\u76d1\u542c\u6570\u636e\u3001\u7ed1\u5b9a\u66f4\u65b0\u51fd\u6570\u7684\u5904\u7406\u662f\u5728<code>compileUtil.bind()<\/code>\u8fd9\u4e2a\u65b9\u6cd5\u4e2d\uff0c\u901a\u8fc7<code>new Watcher()<\/code>\u6dfb\u52a0\u56de\u8c03\u6765\u63a5\u6536\u6570\u636e\u53d8\u5316\u7684\u901a\u77e5<\/p>\n\n\n\n<p>\u81f3\u6b64\uff0c\u4e00\u4e2a\u7b80\u5355\u7684Compile\u5c31\u5b8c\u6210\u4e86\uff0c<a rel=\"noreferrer noopener\" href=\"https:\/\/link.segmentfault.com\/?enc=qe%2BPDCiDznhbxJpIoJGqkg%3D%3D.Lmma9%2FwNu7qc0u%2B8BYb6AXyB%2BNitrru3LtvzTTByZuf%2F6G%2B5ihyQM7tum9euhPdWBw4oEQW0TbmuEjJN6i%2BjPw%3D%3D\" target=\"_blank\">\u5b8c\u6574\u4ee3\u7801<\/a>\u3002\u63a5\u4e0b\u6765\u8981\u770b\u770bWatcher\u8fd9\u4e2a\u8ba2\u9605\u8005\u7684\u5177\u4f53\u5b9e\u73b0\u4e86<\/p>\n\n\n\n<p><strong>3\u3001\u5b9e\u73b0Watcher<\/strong><\/p>\n\n\n\n<p>Watcher\u8ba2\u9605\u8005\u4f5c\u4e3aObserver\u548cCompile\u4e4b\u95f4\u901a\u4fe1\u7684\u6865\u6881\uff0c\u4e3b\u8981\u505a\u7684\u4e8b\u60c5\u662f:<br>1\u3001\u5728\u81ea\u8eab\u5b9e\u4f8b\u5316\u65f6\u5f80\u5c5e\u6027\u8ba2\u9605\u5668(dep)\u91cc\u9762\u6dfb\u52a0\u81ea\u5df1<br>2\u3001\u81ea\u8eab\u5fc5\u987b\u6709\u4e00\u4e2aupdate()\u65b9\u6cd5<br>3\u3001\u5f85\u5c5e\u6027\u53d8\u52a8dep.notice()\u901a\u77e5\u65f6\uff0c\u80fd\u8c03\u7528\u81ea\u8eab\u7684update()\u65b9\u6cd5\uff0c\u5e76\u89e6\u53d1Compile\u4e2d\u7ed1\u5b9a\u7684\u56de\u8c03\uff0c\u5219\u529f\u6210\u8eab\u9000\u3002<br>\u5982\u679c\u6709\u70b9\u4e71\uff0c\u53ef\u4ee5\u56de\u987e\u4e0b\u524d\u9762\u7684\u601d\u8def\u6574\u7406<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function Watcher(vm, exp, cb) {\n    this.cb = cb;\n    this.vm = vm;\n    this.exp = exp;\n    \/\/ \u6b64\u5904\u4e3a\u4e86\u89e6\u53d1\u5c5e\u6027\u7684getter\uff0c\u4ece\u800c\u5728dep\u6dfb\u52a0\u81ea\u5df1\uff0c\u7ed3\u5408Observer\u66f4\u6613\u7406\u89e3\n    this.value = this.get(); \n}\nWatcher.prototype = {\n    update: function() {\n        this.run();    \/\/ \u5c5e\u6027\u503c\u53d8\u5316\u6536\u5230\u901a\u77e5\n    },\n    run: function() {\n        var value = this.get(); \/\/ \u53d6\u5230\u6700\u65b0\u503c\n        var oldVal = this.value;\n        if (value !== oldVal) {\n            this.value = value;\n            this.cb.call(this.vm, value, oldVal); \/\/ \u6267\u884cCompile\u4e2d\u7ed1\u5b9a\u7684\u56de\u8c03\uff0c\u66f4\u65b0\u89c6\u56fe\n        }\n    },\n    get: function() {\n        Dep.target = this;    \/\/ \u5c06\u5f53\u524d\u8ba2\u9605\u8005\u6307\u5411\u81ea\u5df1\n        var value = this.vm[exp];    \/\/ \u89e6\u53d1getter\uff0c\u6dfb\u52a0\u81ea\u5df1\u5230\u5c5e\u6027\u8ba2\u9605\u5668\u4e2d\n        Dep.target = null;    \/\/ \u6dfb\u52a0\u5b8c\u6bd5\uff0c\u91cd\u7f6e\n        return value;\n    }\n};\n\/\/ \u8fd9\u91cc\u518d\u6b21\u5217\u51faObserver\u548cDep\uff0c\u65b9\u4fbf\u7406\u89e3\nObject.defineProperty(data, key, {\n    get: function() {\n        \/\/ \u7531\u4e8e\u9700\u8981\u5728\u95ed\u5305\u5185\u6dfb\u52a0watcher\uff0c\u6240\u4ee5\u53ef\u4ee5\u5728Dep\u5b9a\u4e49\u4e00\u4e2a\u5168\u5c40target\u5c5e\u6027\uff0c\u6682\u5b58watcher, \u6dfb\u52a0\u5b8c\u79fb\u9664\n        Dep.target &amp;&amp; dep.addDep(Dep.target);\n        return val;\n    }\n    \/\/ ... \u7701\u7565\n});\nDep.prototype = {\n    notify: function() {\n        this.subs.forEach(function(sub) {\n            sub.update(); \/\/ \u8c03\u7528\u8ba2\u9605\u8005\u7684update\u65b9\u6cd5\uff0c\u901a\u77e5\u53d8\u5316\n        });\n    }\n};<\/pre>\n\n\n\n<p>\u5b9e\u4f8b\u5316<code>Watcher<\/code>\u7684\u65f6\u5019\uff0c\u8c03\u7528<code>get()<\/code>\u65b9\u6cd5\uff0c\u901a\u8fc7<code>Dep.target = watcherInstance<\/code>\u6807\u8bb0\u8ba2\u9605\u8005\u662f\u5f53\u524dwatcher\u5b9e\u4f8b\uff0c\u5f3a\u884c\u89e6\u53d1\u5c5e\u6027\u5b9a\u4e49\u7684<code>getter<\/code>\u65b9\u6cd5\uff0c<code>getter<\/code>\u65b9\u6cd5\u6267\u884c\u7684\u65f6\u5019\uff0c\u5c31\u4f1a\u5728\u5c5e\u6027\u7684\u8ba2\u9605\u5668<code>dep<\/code>\u6dfb\u52a0\u5f53\u524dwatcher\u5b9e\u4f8b\uff0c\u4ece\u800c\u5728\u5c5e\u6027\u503c\u6709\u53d8\u5316\u7684\u65f6\u5019\uff0cwatcherInstance\u5c31\u80fd\u6536\u5230\u66f4\u65b0\u901a\u77e5\u3002<\/p>\n\n\n\n<p>ok, Watcher\u4e5f\u5df2\u7ecf\u5b9e\u73b0\u4e86\uff0c<a href=\"https:\/\/link.segmentfault.com\/?enc=piu8aUoNH57JR39%2BBbErhw%3D%3D.eBcoM0fehvjNpVM1j3aXGHcRK%2BsY7gIHvhvjgrApunAlnRxx4n0h0K5z%2BGJp3OVbK0ZPFzid2%2FcIPIVqwf%2FP9Q%3D%3D\" rel=\"noreferrer noopener\" target=\"_blank\">\u5b8c\u6574\u4ee3\u7801<\/a>\u3002<br>\u57fa\u672c\u4e0avue\u4e2d\u6570\u636e\u7ed1\u5b9a\u76f8\u5173\u6bd4\u8f83\u6838\u5fc3\u7684\u51e0\u4e2a\u6a21\u5757\u4e5f\u662f\u8fd9\u51e0\u4e2a\uff0c\u731b\u6233<a href=\"https:\/\/link.segmentfault.com\/?enc=1Oo%2Bamjq%2Fu3NPz%2BCaFMTuQ%3D%3D.tBkUu7XfyRElutaHMGIEnzj4PG9FLNWXuPniXIHsp4Y%3D\" rel=\"noreferrer noopener\" target=\"_blank\">\u8fd9\u91cc<\/a> , \u5728<code>src<\/code> \u76ee\u5f55\u53ef\u627e\u5230vue\u6e90\u7801\u3002<\/p>\n\n\n\n<p>\u6700\u540e\u6765\u8bb2\u8bb2MVVM\u5165\u53e3\u6587\u4ef6\u7684\u76f8\u5173\u903b\u8f91\u548c\u5b9e\u73b0\u5427\uff0c\u76f8\u5bf9\u5c31\u6bd4\u8f83\u7b80\u5355\u4e86~<\/p>\n\n\n\n<p><strong>4\u3001\u5b9e\u73b0MVVM<\/strong><\/p>\n\n\n\n<p>MVVM\u4f5c\u4e3a\u6570\u636e\u7ed1\u5b9a\u7684\u5165\u53e3\uff0c\u6574\u5408Observer\u3001Compile\u548cWatcher\u4e09\u8005\uff0c\u901a\u8fc7Observer\u6765\u76d1\u542c\u81ea\u5df1\u7684model\u6570\u636e\u53d8\u5316\uff0c\u901a\u8fc7Compile\u6765\u89e3\u6790\u7f16\u8bd1\u6a21\u677f\u6307\u4ee4\uff0c\u6700\u7ec8\u5229\u7528Watcher\u642d\u8d77Observer\u548cCompile\u4e4b\u95f4\u7684\u901a\u4fe1\u6865\u6881\uff0c\u8fbe\u5230\u6570\u636e\u53d8\u5316 -&gt; \u89c6\u56fe\u66f4\u65b0\uff1b\u89c6\u56fe\u4ea4\u4e92\u53d8\u5316(input) -&gt; \u6570\u636emodel\u53d8\u66f4\u7684\u53cc\u5411\u7ed1\u5b9a\u6548\u679c\u3002<\/p>\n\n\n\n<p>\u4e00\u4e2a\u7b80\u5355\u7684MVVM\u6784\u9020\u5668\u662f\u8fd9\u6837\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function MVVM(options) {\n    this.$options = options;\n    var data = this._data = this.$options.data;\n    observe(data, this);\n    this.$compile = new Compile(options.el || document.body, this)\n}<\/pre>\n\n\n\n<p>\u4f46\u662f\u8fd9\u91cc\u6709\u4e2a\u95ee\u9898\uff0c\u4ece\u4ee3\u7801\u4e2d\u53ef\u770b\u51fa\u76d1\u542c\u7684\u6570\u636e\u5bf9\u8c61\u662foptions.data\uff0c\u6bcf\u6b21\u9700\u8981\u66f4\u65b0\u89c6\u56fe\uff0c\u5219\u5fc5\u987b\u901a\u8fc7<code>var vm = new MVVM({data:{name: 'kindeng'}}); vm._data.name = 'dmq'; <\/code>\u8fd9\u6837\u7684\u65b9\u5f0f\u6765\u6539\u53d8\u6570\u636e\u3002<\/p>\n\n\n\n<p>\u663e\u7136\u4e0d\u7b26\u5408\u6211\u4eec\u4e00\u5f00\u59cb\u7684\u671f\u671b\uff0c\u6211\u4eec\u6240\u671f\u671b\u7684\u8c03\u7528\u65b9\u5f0f\u5e94\u8be5\u662f\u8fd9\u6837\u7684\uff1a<br><code>var vm = new MVVM({data: {name: 'kindeng'}}); vm.name = 'dmq';<\/code><\/p>\n\n\n\n<p>\u6240\u4ee5\u8fd9\u91cc\u9700\u8981\u7ed9MVVM\u5b9e\u4f8b\u6dfb\u52a0\u4e00\u4e2a\u5c5e\u6027\u4ee3\u7406\u7684\u65b9\u6cd5\uff0c\u4f7f\u8bbf\u95eevm\u7684\u5c5e\u6027\u4ee3\u7406\u4e3a\u8bbf\u95eevm._data\u7684\u5c5e\u6027\uff0c\u6539\u9020\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function MVVM(options) {\n    this.$options = options;\n    var data = this._data = this.$options.data, me = this;\n    \/\/ \u5c5e\u6027\u4ee3\u7406\uff0c\u5b9e\u73b0 vm.xxx -> vm._data.xxx\n    Object.keys(data).forEach(function(key) {\n        me._proxy(key);\n    });\n    observe(data, this);\n    this.$compile = new Compile(options.el || document.body, this)\n}\n\nMVVM.prototype = {\n    _proxy: function(key) {\n        var me = this;\n        Object.defineProperty(me, key, {\n            configurable: false,\n            enumerable: true,\n            get: function proxyGetter() {\n                return me._data[key];\n            },\n            set: function proxySetter(newVal) {\n                me._data[key] = newVal;\n            }\n        });\n    }\n};\n<\/pre>\n\n\n\n<p>\u8fd9\u91cc\u4e3b\u8981\u8fd8\u662f\u5229\u7528\u4e86<code>Object.defineProperty()<\/code>\u8fd9\u4e2a\u65b9\u6cd5\u6765\u52ab\u6301\u4e86vm\u5b9e\u4f8b\u5bf9\u8c61\u7684\u5c5e\u6027\u7684\u8bfb\u5199\u6743\uff0c\u4f7f\u8bfb\u5199vm\u5b9e\u4f8b\u7684\u5c5e\u6027\u8f6c\u6210\u8bfb\u5199\u4e86<code>vm._data<\/code>\u7684\u5c5e\u6027\u503c\uff0c\u8fbe\u5230\u9c7c\u76ee\u6df7\u73e0\u7684\u6548\u679c\uff0c\u54c8\u54c8<\/p>\n\n\n\n<p>\u81f3\u6b64\uff0c\u5168\u90e8\u6a21\u5757\u548c\u529f\u80fd\u5df2\u7ecf\u5b8c\u6210\u4e86\uff0c\u5982\u672c\u6587\u5f00\u5934\u6240\u627f\u8bfa\u7684\u4e24\u70b9\u3002\u4e00\u4e2a\u7b80\u5355\u7684MVVM\u6a21\u5757\u5df2\u7ecf\u5b9e\u73b0\uff0c\u5176\u601d\u60f3\u548c\u539f\u7406\u5927\u90e8\u5206\u6765\u81ea\u7ecf\u8fc7\u7b80\u5316\u6539\u9020\u7684vue<a rel=\"noreferrer noopener\" href=\"https:\/\/link.segmentfault.com\/?enc=IhgYUl8wgTZ0e3zqT6zTYw%3D%3D.Ju%2FSquQoStRZt4a%2F8pNGUyy0jN3o9jwW9yVxU7ik%2Fmc%3D\" target=\"_blank\">\u6e90\u7801<\/a>\uff0c\u731b\u6233<a rel=\"noreferrer noopener\" href=\"https:\/\/link.segmentfault.com\/?enc=CEs0X4v26EreoThouCgv1Q%3D%3D.J39U843o%2B9DzCZ7YfryFB%2BNOdRoNTy4BQ0%2F72q%2FoNHg%3D\" target=\"_blank\">\u8fd9\u91cc<\/a>\u53ef\u4ee5\u770b\u5230\u672c\u6587\u7684\u6240\u6709\u76f8\u5173\u4ee3\u7801\u3002<br>\u7531\u4e8e\u672c\u6587\u5185\u5bb9\u504f\u5b9e\u8df5\uff0c\u6240\u4ee5\u4ee3\u7801\u91cf\u8f83\u591a\uff0c\u4e14\u4e0d\u5b9c\u5217\u51fa\u5927\u7bc7\u5e45\u4ee3\u7801\uff0c\u6240\u4ee5\u5efa\u8bae\u60f3\u6df1\u5165\u4e86\u89e3\u7684\u7ae5\u978b\u53ef\u4ee5\u518d\u6b21\u7ed3\u5408\u672c\u6587\u6e90\u4ee3\u7801\u6765\u8fdb\u884c\u9605\u8bfb\uff0c\u8fd9\u6837\u4f1a\u66f4\u52a0\u5bb9\u6613\u7406\u89e3\u548c\u638c\u63e1\u3002<\/p>\n\n\n\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u672c\u6587\u4e3b\u8981\u56f4\u7ed5\u201c\u51e0\u79cd\u5b9e\u73b0\u53cc\u5411\u7ed1\u5b9a\u7684\u505a\u6cd5\u201d\u3001\u201c\u5b9e\u73b0Observer\u201d\u3001\u201c\u5b9e\u73b0Compile\u201d\u3001\u201c\u5b9e\u73b0Watcher\u201d\u3001\u201c\u5b9e\u73b0MVVM\u201d\u8fd9\u51e0\u4e2a\u6a21\u5757\u6765\u9610\u8ff0\u4e86\u53cc\u5411\u7ed1\u5b9a\u7684\u539f\u7406\u548c\u5b9e\u73b0\u3002\u5e76\u6839\u636e\u601d\u8def\u6d41\u7a0b\u6e10\u8fdb\u68b3\u7406\u8bb2\u89e3\u4e86\u4e00\u4e9b\u7ec6\u8282\u601d\u8def\u548c\u6bd4\u8f83\u5173\u952e\u7684\u5185\u5bb9\u70b9\uff0c\u4ee5\u53ca\u901a\u8fc7\u5c55\u793a\u90e8\u5206\u5173\u952e\u4ee3\u7801\u8bb2\u8ff0\u4e86\u600e\u6837\u4e00\u6b65\u6b65\u5b9e\u73b0\u4e00\u4e2a\u53cc\u5411\u7ed1\u5b9aMVVM\u3002\u6587\u4e2d\u80af\u5b9a\u4f1a\u6709\u4e00\u4e9b\u4e0d\u591f\u4e25\u8c28\u7684\u601d\u8003\u548c\u9519\u8bef\uff0c\u6b22\u8fce\u5927\u5bb6\u6307\u6b63\uff0c\u6709\u5174\u8da3\u6b22\u8fce\u4e00\u8d77\u63a2\u8ba8\u548c\u6539\u8fdb~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u8f7d\uff1ahttps:\/\/segmentfault.com\/a\/1190000006599500 \u672c\u6587\u80fd\u5e2e\u4f60\u505a\u4ec0\u4e48 [&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":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6430"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6430"}],"version-history":[{"count":8,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6430\/revisions"}],"predecessor-version":[{"id":6552,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6430\/revisions\/6552"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}