{"id":2228,"date":"2024-11-10T16:07:31","date_gmt":"2024-11-10T08:07:31","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2228\/"},"modified":"2024-11-10T16:07:31","modified_gmt":"2024-11-10T08:07:31","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%e4%b8%8b%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2228\/","title":{"rendered":"Vue.js 2 \u4e2d\u5982\u4f55\u5c06 VNode \u6570\u7ec4\u63d2\u5165\u5230\u6307\u5b9a\u5143\u7d20\u4e0b\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173069514390806.jpg\" class=\"aligncenter\" title=\"Vue.js 2 \u4e2d\u5982\u4f55\u5c06 VNode \u6570\u7ec4\u63d2\u5165\u5230\u6307\u5b9a\u5143\u7d20\u4e0b\uff1f\u63d2\u56fe\" alt=\"Vue.js 2 \u4e2d\u5982\u4f55\u5c06 VNode \u6570\u7ec4\u63d2\u5165\u5230\u6307\u5b9a\u5143\u7d20\u4e0b\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>.js 2 vnode\u6570\u7ec4\u63d2\u5165\u5230\u6307\u5b9a\u5143\u7d20\u4e0b\u7684\u4e24\u79cd\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u5bf9\u4e8e\u95ee\u98981\uff1a<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u68481<\/strong><\/p>\n<pre>import Vue from \"vue\";\nimport nodeRenderer from \".\/RenderNode\";\nconst DetailConstructor = Vue.extend(nodeRenderer);\nexport default {\n  props: {\n    fullText: \"\",\n  },\n  mounted() {\n    \/\/ \u53c2\u8003 https:\/\/stackoverflow.com\/a\/50937178\/3089701\n    const detailRenderer = new DetailConstructor({\n      propsData: {\n        node: this.$slots.default,\n      },\n    });\n    console.log(detailRenderer.$mount(), detailRenderer.$el.outerHTML); \/\/ $el\u662fdom\u5bf9\u8c61\uff0c\u4efb\u610f\u64cd\u4f5c\n  },\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5bf9\u5e94RenderNode.js\uff1a<\/strong><\/p>\n<pre>export default {\n  props: [\"node\"],\n  render(h, context) {\n    return this.node ? this.node : \"\";\n  },\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u89e3\u51b3\u65b9\u68482<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>const slot = this.$slots.default[0];\nconsole.log(slot.context.$mount(), slot.context.$el.innerHTML);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5bf9\u4e8e\u95ee\u98982\uff1a\u62ff\u5230DOM\u540e\uff0c\u53ef\u4ee5\u8fdb\u884c\u4efb\u610f\u64cd\u4f5c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fVue.js 2 \u4e2d\u5982\u4f55\u5c06 VNode \u6570\u7ec4\u63d2\u5165\u5230\u6307\u5b9a\u5143\u7d20\u4e0b\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 vnode\u6570\u7ec4\u63d2\u5165\u5230\u6307\u5b9a\u5143\u7d20\u4e0b\u7684\u4e24\u79cd\u89e3\u51b3\u65b9\u6848 \u5bf9\u4e8e\u95ee\u98981\uff1a \u89e3\u51b3\u65b9\u68481 import Vue from &#8220;vue&#8221;; import nodeRenderer from &#8220;.\/RenderNode&#8221;; const DetailConstructor = Vue.extend(nodeRenderer); export default { props: { fullText: &#8220;&#8221;, }, mounted() { \/\/ \u53c2\u8003 https:\/\/stackoverflow.com\/a\/50937178\/3089701 const detailRenderer = new DetailConstructor({ propsData: { node: this.$slots.default, }, }); console.log(detailRenderer.$mount(), detailRenderer.$el.outerHTML); \/\/ $el\u662fdom\u5bf9\u8c61\uff0c\u4efb\u610f\u64cd\u4f5c }, }; \u767b\u5f55\u540e\u590d\u5236 \u5bf9\u5e94RenderNode.js\uff1a export default { props: [&#8220;node&#8221;], render(h, [&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-2228","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2228","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=2228"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2228\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}