{"id":2302,"date":"2024-11-10T08:11:33","date_gmt":"2024-11-10T00:11:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2302\/"},"modified":"2024-11-10T08:11:33","modified_gmt":"2024-11-10T00:11:33","slug":"vue-js-2-%e4%b8%ad%e5%a6%82%e4%bd%95%e5%b0%86-vnode-%e6%95%b0%e7%bb%84%e6%8f%92%e5%85%a5%e5%88%b0%e6%8c%87%e5%ae%9a%e5%85%83%e7%b4%a0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2302\/","title":{"rendered":"Vue.js 2 \u4e2d\u5982\u4f55\u5c06 VNode \u6570\u7ec4\u63d2\u5165\u5230\u6307\u5b9a\u5143\u7d20\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173071104720996.jpg\" class=\"aligncenter\" title=\"Vue.js 2 \u4e2d\u5982\u4f55\u5c06 VNode \u6570\u7ec4\u63d2\u5165\u5230\u6307\u5b9a\u5143\u7d20\uff1f\u63d2\u56fe\" alt=\"Vue.js 2 \u4e2d\u5982\u4f55\u5c06 VNode \u6570\u7ec4\u63d2\u5165\u5230\u6307\u5b9a\u5143\u7d20\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>.js 2 \u5982\u4f55\u5c06 vnode \u6570\u7ec4\u63d2\u5165\u5230\u6307\u5b9a\u5143\u7d20\u4e2d<\/strong><\/p>\n<p><strong>\u95ee\u9898\u7684\u63d0\u51fa\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528 Vue.js 2 \u5f00\u53d1\u65f6\uff0c\u9700\u8981\u5c06 VNode \u6570\u7ec4\u63d2\u5165\u5230\u7ec4\u4ef6\u7684\u67d0\u4e2a\u5143\u7d20\u4e2d\u3002\u4f46\u9047\u5230\u4ee5\u4e0b\u95ee\u9898\uff1a<\/p>\n<ul>\n<li> <strong>\u95ee\u9898 1\uff1a<\/strong>\u5982\u4f55\u83b7\u53d6\u5143\u7d20\u7684 InnerHTML\uff1f<\/li>\n<li> <strong>\u95ee\u9898 2\uff1a<\/strong>\u5728\u65e0\u6cd5\u83b7\u53d6 InnerHTML \u7684\u60c5\u51b5\u4e0b\uff0c\u5982\u4f55\u5c06 VNode \u6570\u7ec4\u63d2\u5165\u5230\u6307\u5b9a\u7684\u5143\u7d20\u4e2d\uff1f<\/li>\n<\/ul>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p><strong>\u95ee\u9898 1\uff1a\u83b7\u53d6 InnerHTML<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u8981\u83b7\u53d6 InnerHTML\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u81ea\u5b9a\u4e49\u7ec4\u4ef6\uff1a<\/p>\n<pre>import Vue from \"vue\";\nimport nodeRenderer from \".\/RenderNode\";\n\nconst DetailConstructor = Vue.extend(nodeRenderer);\n\nexport default {\n  props: {\n    fullText: \"\",\n  },\n  mounted() {\n    \/\/ \u89e3\u51b3\u65b9\u6848 1\n    const detailRenderer = new DetailConstructor({\n      propsData: {\n        node: this.$slots.default,\n      },\n    });\n    console.log(detailRenderer.$mount(), detailRenderer.$el.outerHTML); \/\/ $el \u662f DOM \u5bf9\u8c61\uff0c\u53ef\u8fdb\u884c\u4efb\u610f\u64cd\u4f5c\n\n    \/\/ \u89e3\u51b3\u65b9\u6848 2\n    const slot = this.$slots.default[0];\n    console.log(slot.context.$mount(), slot.context.$el.innerHTML);\n  },\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a\u95ee\u9898 2\uff1a\u63d2\u5165 VNode \u6570\u7ec4<\/strong><\/p>\n<p>\u83b7\u53d6\u5230 DOM \u540e\uff0c\u53ef\u4ee5\u4f7f\u7528 DOM API \u5c06 VNode \u6570\u7ec4\u63d2\u5165\u5230\u6307\u5b9a\u7684\u5143\u7d20\u4e2d\u3002<\/p>\n<pre>\/\/ ...\n\nmounted() {\n  \/\/ ...\n\n  \/\/ \u83b7\u53d6 DOM \u8282\u70b9\n  const el = this.$refs.fullText;\n\n  \/\/ \u6e05\u7a7a\u5143\u7d20\u5185\u5bb9\n  el.innerHTML = \"\";\n\n  \/\/ \u63d2\u5165 VNode \u6570\u7ec4\n  this.$slots.default.forEach((vnode) =&gt; {\n    el.appendChild(vnode.elm);\n  });\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fVue.js 2 \u4e2d\u5982\u4f55\u5c06 VNode \u6570\u7ec4\u63d2\u5165\u5230\u6307\u5b9a\u5143\u7d20\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>.js 2 \u5982\u4f55\u5c06 vnode \u6570\u7ec4\u63d2\u5165\u5230\u6307\u5b9a\u5143\u7d20\u4e2d \u95ee\u9898\u7684\u63d0\u51fa\uff1a \u4f7f\u7528 Vue.js 2 \u5f00\u53d1\u65f6\uff0c\u9700\u8981\u5c06 VNode \u6570\u7ec4\u63d2\u5165\u5230\u7ec4\u4ef6\u7684\u67d0\u4e2a\u5143\u7d20\u4e2d\u3002\u4f46\u9047\u5230\u4ee5\u4e0b\u95ee\u9898\uff1a \u95ee\u9898 1\uff1a\u5982\u4f55\u83b7\u53d6\u5143\u7d20\u7684 InnerHTML\uff1f \u95ee\u9898 2\uff1a\u5728\u65e0\u6cd5\u83b7\u53d6 InnerHTML \u7684\u60c5\u51b5\u4e0b\uff0c\u5982\u4f55\u5c06 VNode \u6570\u7ec4\u63d2\u5165\u5230\u6307\u5b9a\u7684\u5143\u7d20\u4e2d\uff1f \u89e3\u51b3\u65b9\u6848\uff1a \u95ee\u9898 1\uff1a\u83b7\u53d6 InnerHTML \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u8981\u83b7\u53d6 InnerHTML\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u81ea\u5b9a\u4e49\u7ec4\u4ef6\uff1a import Vue from &#8220;vue&#8221;; import nodeRenderer from &#8220;.\/RenderNode&#8221;; const DetailConstructor = Vue.extend(nodeRenderer); export default { props: { fullText: &#8220;&#8221;, }, mounted() { \/\/ \u89e3\u51b3\u65b9\u6848 1 const detailRenderer [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-2302","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=2302"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2302\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}