{"id":2280,"date":"2024-11-10T17:22:36","date_gmt":"2024-11-10T09:22:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2280\/"},"modified":"2024-11-10T17:22:36","modified_gmt":"2024-11-10T09:22:36","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-vue-js-2-%e4%b8%ad%e8%8e%b7%e5%8f%96-vnode-%e6%95%b0%e7%bb%84%e7%9a%84-innerhtml-%e5%b9%b6%e6%8f%92%e5%85%a5%e5%88%b0%e7%89%b9%e5%ae%9a%e5%85%83%e7%b4%a0%e4%b8%ad%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2280\/","title":{"rendered":"\u5982\u4f55\u5728 Vue.js 2 \u4e2d\u83b7\u53d6 VNode \u6570\u7ec4\u7684 InnerHTML \u5e76\u63d2\u5165\u5230\u7279\u5b9a\u5143\u7d20\u4e2d\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173070486368755.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728 Vue.js 2 \u4e2d\u83b7\u53d6 VNode \u6570\u7ec4\u7684 InnerHTML \u5e76\u63d2\u5165\u5230\u7279\u5b9a\u5143\u7d20\u4e2d\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728 Vue.js 2 \u4e2d\u83b7\u53d6 VNode \u6570\u7ec4\u7684 InnerHTML \u5e76\u63d2\u5165\u5230\u7279\u5b9a\u5143\u7d20\u4e2d\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>.js 2 \u4e2d vnode \u6570\u7ec4\u63d2\u5165<\/strong><\/p>\n<p>\u5728 Vue.js 2 \u4e2d\uff0c\u901a\u8fc7 this.$slots.default \u83b7\u53d6\u7684 VNode \u6570\u7ec4\u4ee3\u8868\u4e86\u5b50\u7ec4\u4ef6\u7684\u5185\u5bb9\u3002\u672c\u6587\u5c06\u63a2\u8ba8\u5982\u4f55\u83b7\u53d6 VNode \u7684 InnerHTML \u4ee5\u53ca\u5c06\u5176\u63d2\u5165\u5230\u7ec4\u4ef6\u7684\u7279\u5b9a\u5143\u7d20\u4e2d\u3002<\/p>\n<p><strong>\u83b7\u53d6 VNode \u7684 InnerHTML<\/strong><\/p>\n<p>\u76f4\u63a5\u83b7\u53d6 VNode \u7684 InnerHTML \u5e76\u4e0d\u80fd\u83b7\u5f97\u9884\u671f\u7684\u7ed3\u679c\u3002\u4e0d\u8fc7\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<pre>const detailRenderer = new DetailConstructor({\n  propsData: {\n    node: this.$slots.default,\n  },\n});\n\nconsole.log(detailRenderer.$mount(), detailRenderer.$el.outerHTML);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff0cDetlConstructor \u662f\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7ec4\u4ef6\uff0c\u7528\u4e8e\u6e32\u67d3 VNode\u3002\u6e32\u67d3\u540e\u7684 DOM \u53ef\u901a\u8fc7 outerHTML \u5c5e\u6027\u83b7\u53d6\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u63d2\u5165 VNode \u5230\u7279\u5b9a\u5143\u7d20<\/strong><\/p>\n<p>\u83b7\u53d6 DOM \u540e\uff0c\u53ef\u6839\u636e\u9700\u8981\u8fdb\u884c\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u5c06 VNode \u63d2\u5165\u7ec4\u4ef6 fullText \u5143\u7d20\u4e2d\uff1a<\/p>\n<pre>const slot = this.$slots.default[0];\nthis.$refs.fullText.appendChild(slot.context.$mount().$el);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff0cthis.$refs.fullText \u5f15\u7528\u4e86\u7ec4\u4ef6\u7684 fullText \u5143\u7d20\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728 Vue.js 2 \u4e2d\u83b7\u53d6 VNode \u6570\u7ec4\u7684 InnerHTML \u5e76\u63d2\u5165\u5230\u7279\u5b9a\u5143\u7d20\u4e2d\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 \u4e2d vnode \u6570\u7ec4\u63d2\u5165 \u5728 Vue.js 2 \u4e2d\uff0c\u901a\u8fc7 this.$slots.default \u83b7\u53d6\u7684 VNode \u6570\u7ec4\u4ee3\u8868\u4e86\u5b50\u7ec4\u4ef6\u7684\u5185\u5bb9\u3002\u672c\u6587\u5c06\u63a2\u8ba8\u5982\u4f55\u83b7\u53d6 VNode \u7684 InnerHTML \u4ee5\u53ca\u5c06\u5176\u63d2\u5165\u5230\u7ec4\u4ef6\u7684\u7279\u5b9a\u5143\u7d20\u4e2d\u3002 \u83b7\u53d6 VNode \u7684 InnerHTML \u76f4\u63a5\u83b7\u53d6 VNode \u7684 InnerHTML \u5e76\u4e0d\u80fd\u83b7\u5f97\u9884\u671f\u7684\u7ed3\u679c\u3002\u4e0d\u8fc7\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a const detailRenderer = new DetailConstructor({ propsData: { node: this.$slots.default, }, }); console.log(detailRenderer.$mount(), detailRenderer.$el.outerHTML); \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff0cDetlConstructor \u662f\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7ec4\u4ef6\uff0c\u7528\u4e8e\u6e32\u67d3 VNode\u3002\u6e32\u67d3\u540e\u7684 DOM \u53ef\u901a\u8fc7 outerHTML \u5c5e\u6027\u83b7\u53d6\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u63d2\u5165 VNode \u5230\u7279\u5b9a\u5143\u7d20 \u83b7\u53d6 DOM \u540e\uff0c\u53ef\u6839\u636e\u9700\u8981\u8fdb\u884c\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u5c06 VNode [&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-2280","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2280","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=2280"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2280\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}