{"id":187115,"date":"2020-10-28T22:20:05","date_gmt":"2020-10-28T14:20:05","guid":{"rendered":"http:\/\/4563.org\/?p=187115"},"modified":"2020-10-28T22:20:05","modified_gmt":"2020-10-28T14:20:05","slug":"vue-%e7%83%ad%e6%9b%b4%e6%96%b0%e7%9a%84%e6%97%b6%e5%80%99%ef%bc%8c%e4%bd%bf%e7%94%a8-document-%e8%8e%b7%e5%8f%96%e5%88%b0%e7%9a%84-dom-%e5%85%83%e7%b4%a0%e9%87%8c%e9%9d%a2%e5%8c%85%e5%90%ab%e7%9a%84","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=187115","title":{"rendered":"vue \u70ed\u66f4\u65b0\u7684\u65f6\u5019\uff0c\u4f7f\u7528 document \u83b7\u53d6\u5230\u7684 dom \u5143\u7d20\u91cc\u9762\u5305\u542b\u7684\u5185\u5bb9\u4f1a\u6d88\u5931\uff0c\u4f46\u662f ref \u83b7\u53d6\u5230\u7684\u4e0d\u4f1a\u6d88\u5931\uff0c\u8fd9\u662f\u4e3a\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5728 vue \u4e2d\u83b7\u53d6 dom \u4f7f\u7528 ref\uff0c\u800c\u4e0d\u9002\u7528 document\uff0c\u6709\u4ec0\u4e48\u533a\u522b\u5417\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  vue \u70ed\u66f4\u65b0\u7684\u65f6\u5019\uff0c\u4f7f\u7528 document \u83b7\u53d6\u5230\u7684 dom \u5143\u7d20\u91cc\u9762\u5305\u542b\u7684\u5185\u5bb9\u4f1a\u6d88\u5931\uff0c\u4f46\u662f ref \u83b7\u53d6\u5230\u7684\u4e0d\u4f1a\u6d88\u5931\uff0c\u8fd9\u662f\u4e3a\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5728 vue \u4e2d\u83b7\u53d6 dom \u4f7f\u7528 ref\uff0c\u800c\u4e0d\u9002\u7528 document\uff0c\u6709\u4ec0\u4e48\u533a\u522b\u5417\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Pokemon123 <\/span>  <span><i><\/i> 6<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        vue \u4e2d\u7684 dom \u90fd\u662f\u865a\u62df DOM \u6e32\u67d3\u7684\uff0c\u5728\u6ca1\u6709\u6e32\u67d3\u5b8c\u6bd5\u4e4b\u524d document \u662f\u83b7\u53d6\u4e0d\u5230\u7684      <\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>10<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4051359\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : tanranran <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             ref \u5230\u7684 DOM\uff0c\u5e94\u8be5\u662f\u5185\u5b58\u91cc\u9762\u7684\u865a\u62df DOM<br \/>document \u5219\u662f\u5b9e\u6253\u5b9e\u7684 DOM\uff0c\u6e32\u67d3\u7684\u65f6\u5019\u88ab\u66ff\u6362\u6210 &lt;!&#8212;-&gt; \u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4051360\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ragnaroks <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ragnaroks \u4e5f\u5c31\u662f\u8bf4\u5728\u6ca1\u6709\u6e32\u67d3\u5b8c\u6bd5\u4e4b\u524d\uff0c\u771f\u5b9e\u7684 dom \u91cc\u9762\u7684\u5185\u5bb9\u5168\u662f&lt;!&#8212;-&gt;\uff0c\u6240\u4ee5\u6211\u83b7\u53d6\u5230\u7684 dom \u91cc\u9762\u7684\u5185\u5bb9\u662f\u7a7a\u7684\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4051361\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Pokemon123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             setTimeout \u89e3\u51b3\u4e00\u5207\u7591\u96be\u6742\u75c7                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4051362\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xiangyuecn <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @xiangyuecn \u53ef\u4ee5\u518d\u8bf4\u7684\u8be6\u7ec6\u4e00\u4e9b\u5417\u263a\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4051363\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Pokemon123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u770b\u4e0b vue \u7684 nexttick \u5c31\u4e86\u89e3\u4e86,\u6709\u63d0\u5230 dom                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4051364\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ragnaroks <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ragnaroks \u597d\u7684\uff0c\u8c22\u8c22\u2740                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4051365\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Pokemon123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53ef\u522b\u542c\u4e0a\u7684 setTimeout\uff0c\u662f\u6709\u591a\u5927\u7684\u2764\ufe0f\u624d\u4f1a\u7528\u8fd9\u4e2a\u8822\u529e\u6cd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4051366\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hongch <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             ref \u91cc\u5b58\u7684\u5e94\u8be5\u662f vue \u81ea\u5df1\u7684\u4e00\u4e2a\u5bf9\u8c61\uff0c\u6709\u81ea\u5df1\u7684\u552f\u4e00 key \u503c\u4e0e\u5b9e\u4f53 dom \u505a\u5bf9\u5e94\uff0c\u5728 vue \u66f4\u65b0\u8282\u70b9\u540e\u66f4\u65b0\u4e24\u8005\u4e4b\u95f4\u7684\u8054\u7cfb\u3002setTimeout \u7684\u65b9\u6cd5\u662f\uff0c\u5229\u7528 marco queue \u8fd0\u884c\u6bd4 .nextTick \u548c promise \u4f18\u5148\u7ea7\u6162\u7684\u7279\u70b9\uff0c\u4f01\u56fe\u5728 vue \u66f4\u65b0 dom \u8282\u70b9\u540e\u5728\u53bb\u7528 document \u83b7\u53d6\uff0c\u4e0d\u662f\u62ff\u4e0d\u5230\uff0chtml \u4e0a\u7684\u8282\u70b9\u600e\u4e48\u53ef\u80fd\u62ff\u4e0d\u5230\u3002\u5c31\u662f\u4e0d\u592a\u7b26\u5408 vue \u7684\u601d\u60f3                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4051367\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : azcvcza <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5728 vue \u7ba1\u7406\u4e0b\u7684 dom \u8282\u70b9\u662f\u4f1a\u66f4\u65b0\u7684\uff0c <br \/>\u6bd4\u5982\u4f60\u7528 var nodeNoRef = document.querySelecotr(&#8216;.xx-node&#8217;) \u62ff\u5230\u4e00\u4e2a\u8282\u70b9\uff0c<br \/>vue \u89e6\u53d1\u70ed\u66f4\u65b0(\u6216\u8005\u662f update)\u4e4b\u540e\uff0c\u4e0a\u9762\u7684 nodeNoRef \u5c31\u53ef\u80fd\u5df2\u7ecf\u4e0d\u5728 document \u4e2d\u4e86\uff0c\u53ea\u662f\u4e00\u4e2a\u5373\u5c06\u88ab\u56de\u6536\u7684\u5bf9\u8c61\u3002<br \/>\u89e3\u51b3\u65b9\u6cd5\uff1a<br \/>1. \u6bcf\u6b21\u4f7f\u7528 DOM \u90fd\u7528 Vue \u7684$ref \u83b7\u53d6 ;<br \/>2. \u5728\u5fc5\u8981\u65f6\u4f7f\u7528$nextTick \u3002 \u5e38\u89c1\u573a\u666f\uff1adata \u66f4\u65b0\u540e\uff0c\u9700\u8981\u7acb\u5373\u83b7\u53d6 DOM\uff0c\u53ef\u80fd\u9700\u8981\u5728$nextTick \u4e2d\u6765\u83b7\u53d6 DOM \u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4051368\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : meepo3927 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @meepo3927 \u90a3\u6211\u4f7f\u7528$ref \u83b7\u53d6 dom \u7684\u65f6\u5019\uff0c\u6b64\u65f6\u9875\u9762\u4e0a\u8fd8\u6ca1\u6709\u6e32\u67d3\u771f\u6b63\u7684 dom \u5bf9\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>vue \u70ed\u66f4\u65b0\u7684\u65f6\u5019\uff0c\u4f7f\u7528 doc&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/187115"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=187115"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/187115\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=187115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=187115"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=187115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}