{"id":57858,"date":"2025-08-15T21:19:59","date_gmt":"2025-08-15T13:19:59","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/57858.html"},"modified":"2025-08-15T21:19:59","modified_gmt":"2025-08-15T13:19:59","slug":"vue-3-%e6%b8%b2%e6%9f%93%e5%87%bd%e6%95%b0%e8%bf%9b%e9%98%b6%e6%8c%87%e5%8d%97%ef%bc%9ah-mergeprops-clonevnode-%e7%ad%89%e6%a0%b8%e5%bf%83-api-%e6%b7%b1%e5%ba%a6%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/57858.html","title":{"rendered":"Vue 3 \u6e32\u67d3\u51fd\u6570\u8fdb\u9636\u6307\u5357\uff1ah(), mergeProps(), cloneVNode() \u7b49\u6838\u5fc3 API \u6df1\u5ea6\u89e3\u6790"},"content":{"rendered":"<h5>\u5f15\u8a00<\/h5>\n<p>\u5728 Vue 3 \u7684\u4e16\u754c\u91cc&#xff0c;&lt;template&gt; \u8bed\u6cd5\u56e0\u5176\u7b80\u6d01\u3001\u76f4\u89c2\u800c\u5e7f\u53d7\u6b22\u8fce\u3002\u7136\u800c&#xff0c;\u5f53\u4f60\u7684\u9700\u6c42\u53d8\u5f97\u590d\u6742&#xff0c;\u9700\u8981\u52a8\u6001\u521b\u5efa\u7ec4\u4ef6\u3001\u8fdb\u884c\u9ad8\u7ea7\u7ec4\u4ef6\u62bd\u8c61\u3001\u6216\u6784\u5efa UI \u5e93\u65f6&#xff0c;&lt;template&gt; \u7684\u9759\u6001\u7279\u6027\u53ef\u80fd\u4f1a\u663e\u5f97\u529b\u4e0d\u4ece\u5fc3\u3002\u8fd9\u65f6&#xff0c;Vue \u63d0\u4f9b\u7684\u6e32\u67d3\u51fd\u6570 (Render Functions) \u5c31\u6210\u4e3a\u4e86\u5f3a\u5927\u7684\u6b66\u5668\u3002<\/p>\n<p>\u6e32\u67d3\u51fd\u6570\u5141\u8bb8\u4f60\u4f7f\u7528 JavaScript \u7684\u5168\u90e8\u80fd\u529b\u6765\u7a0b\u5e8f\u5316\u5730\u63cf\u8ff0 UI\u3002\u4eca\u5929&#xff0c;\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8 Vue 3 \u4e2d\u51e0\u4e2a\u6838\u5fc3\u7684\u6e32\u67d3\u51fd\u6570\u548c\u5de5\u5177\u51fd\u6570&#xff1a;h(), mergeProps(), cloneVNode(), isVNode(), resolveComponent(), resolveDirective(), withDirectives(), \u548c withModifiers()\u3002\u6211\u4eec\u5c06\u9010\u4e00\u89e3\u6790\u5b83\u4eec\u7684\u5b9a\u4e49\u3001\u7528\u6cd5\u3001\u4f18\u52bf&#xff0c;\u5e76\u5c1d\u8bd5\u7528 JavaScript \u4e2d\u7684\u5e38\u89c1\u65b9\u6cd5\u8fdb\u884c\u7c7b\u6bd4&#xff0c;\u5e2e\u52a9\u4f60\u5efa\u7acb\u66f4\u76f4\u89c2\u7684\u7406\u89e3\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a; \u672c\u6587\u5047\u8bbe\u4f60\u5df2\u5177\u5907 Vue 3 \u57fa\u7840\u77e5\u8bc6&#xff08;\u5982 Composition API, setup()&#xff09;\u3002\u6211\u4eec\u5c06\u4e3b\u8981\u5728 setup() \u51fd\u6570\u4e2d\u4f7f\u7528\u8fd9\u4e9b API&#xff0c;\u5b83\u4eec\u901a\u5e38\u4e0e render() \u51fd\u6570\u6216 JSX \u7ed3\u5408\u4f7f\u7528\u3002<\/p>\n<hr \/>\n<h5>1.\u00a0h()&#xff1a;\u521b\u5efa VNode \u7684\u57fa\u77f3<\/h5>\n<ul>\n<li>\u5b9a\u4e49&#xff1a;\u00a0h()\u00a0\u51fd\u6570\u662f\u00a0Hyperscript\u00a0\u7684\u7f29\u5199&#xff0c;\u662f\u521b\u5efa\u865a\u62df DOM \u8282\u70b9&#xff08;VNode&#xff09;\u7684\u6838\u5fc3\u5de5\u5382\u51fd\u6570\u3002\u5b83\u63a5\u6536\u6807\u7b7e\u3001\u5c5e\u6027\/props\/\u4e8b\u4ef6\u3001\u5b50\u8282\u70b9\u7b49\u53c2\u6570&#xff0c;\u8fd4\u56de\u4e00\u4e2a\u63cf\u8ff0 DOM \u8282\u70b9\u6216\u7ec4\u4ef6\u7684 VNode \u5bf9\u8c61\u3002<\/li>\n<li>\u7528\u6cd5&#xff1a;\n<p>import { h } from &#039;vue&#039;<\/p>\n<p>\/\/ \u521b\u5efa\u4e00\u4e2a\u666e\u901a HTML \u5143\u7d20<br \/>\nconst vnode1 &#061; h(&#039;div&#039;, { class: &#039;container&#039;, id: &#039;main&#039; }, [<br \/>\n  h(&#039;h1&#039;, { style: { color: &#039;blue&#039; } }, &#039;Hello World&#039;),<br \/>\n  h(&#039;p&#039;, &#039;This is a paragraph.&#039;)<br \/>\n])<\/p>\n<p>\/\/ \u521b\u5efa\u4e00\u4e2a\u7ec4\u4ef6\u5b9e\u4f8b<br \/>\nconst MyComponent &#061; { \/* \u7ec4\u4ef6\u5b9a\u4e49 *\/ }<br \/>\nconst vnode2 &#061; h(MyComponent, {<br \/>\n  msg: &#039;Hello from h()!&#039;,<br \/>\n  onClick: () &#061;&gt; console.log(&#039;Component clicked!&#039;)<br \/>\n}, [<br \/>\n  \/\/ \u63d2\u69fd\u5185\u5bb9<br \/>\n  h(&#039;template&#039;, { slot: &#039;header&#039; }, &#039;Header Slot Content&#039;),<br \/>\n  &#039;Default Slot Content&#039;<br \/>\n])<\/p>\n<p>\/\/ \u5728 setup() \u4e2d\u8fd4\u56de VNode<br \/>\nexport default {<br \/>\n  setup() {<br \/>\n    return () &#061;&gt; h(&#039;div&#039;, { class: &#039;app&#039; }, &#039;Hello from render function!&#039;)<br \/>\n  }<br \/>\n}\n<\/li>\n<li>\u4f18\u52bf&#xff1a;\n<ul>\n<li>\u5b8c\u5168\u7684\u7f16\u7a0b\u80fd\u529b&#xff1a;\u00a0\u53ef\u4ee5\u5229\u7528\u00a0if,\u00a0for,\u00a0map,\u00a0filter\u00a0\u7b49 JavaScript \u903b\u8f91\u52a8\u6001\u6784\u5efa UI\u3002<\/li>\n<li>\u9ad8\u5ea6\u7075\u6d3b&#xff1a;\u00a0\u80fd\u521b\u5efa\u00a0&lt;template&gt;\u00a0\u65e0\u6cd5\u76f4\u63a5\u8868\u8fbe\u7684\u590d\u6742\u7ed3\u6784\u3002<\/li>\n<li>\u6027\u80fd\u4f18\u5316\u57fa\u7840&#xff1a;\u00a0\u76f4\u63a5\u64cd\u4f5c VNode&#xff0c;\u662f\u6784\u5efa\u9ad8\u6027\u80fd\u3001\u53ef\u590d\u7528\u62bd\u8c61\u7ec4\u4ef6\u7684\u57fa\u7840\u3002<\/li>\n<\/ul>\n<\/li>\n<li>JavaScript \u7c7b\u6bd4&#xff1a;\u00a0h()\u00a0\u7c7b\u4f3c\u4e8e\u00a0document.createElement()\u00a0&#043;\u00a0element.setAttribute()\u00a0&#043;\u00a0element.appendChild()\u00a0\u7684\u7ec4\u5408\u3002\u4f46\u5b83\u66f4\u9ad8\u7ea7&#xff0c;\u56e0\u4e3a\u5b83\u521b\u5efa\u7684\u662f\u865a\u62df\u8282\u70b9&#xff0c;\u7531 Vue \u7684\u54cd\u5e94\u5f0f\u7cfb\u7edf\u548c Diff \u7b97\u6cd5\u7ba1\u7406&#xff0c;\u800c\u4e0d\u662f\u76f4\u63a5\u64cd\u4f5c\u771f\u5b9e DOM\u3002\u5b83\u66f4\u50cf\u662f\u4e00\u4e2a\u5de5\u5382\u51fd\u6570&#xff0c;\u6839\u636e\u8f93\u5165\u53c2\u6570\u751f\u6210\u4e00\u4e2a\u63cf\u8ff0 UI \u7684\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<hr \/>\n<h5>2.\u00a0mergeProps()&#xff1a;\u5c5e\u6027\u5408\u5e76\u5927\u5e08<\/h5>\n<ul>\n<li>\u5b9a\u4e49&#xff1a;\u00a0mergeProps()\u00a0\u51fd\u6570\u7528\u4e8e\u5408\u5e76\u591a\u4e2a props \u5bf9\u8c61\u3002\u5b83\u4f1a\u667a\u80fd\u5730\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684 props&#xff08;\u5982\u00a0class,\u00a0style, \u4e8b\u4ef6\u76d1\u542c\u5668&#xff09;&#xff0c;\u786e\u4fdd\u5b83\u4eec\u88ab\u6b63\u786e\u5730\u5408\u5e76&#xff0c;\u800c\u4e0d\u662f\u7b80\u5355\u5730\u8986\u76d6\u3002<\/li>\n<li>\u7528\u6cd5&#xff1a;\n<p>import { h, mergeProps } from &#039;vue&#039;<\/p>\n<p>export default {<br \/>\n  props: {<br \/>\n    \/\/ \u7ec4\u4ef6\u63a5\u6536\u7684 props<br \/>\n    userClass: String,<br \/>\n    userStyle: Object,<br \/>\n    onClick: Function<br \/>\n  },<br \/>\n  setup(props, { slots }) {<br \/>\n    return () &#061;&gt; {<br \/>\n      \/\/ \u5b9a\u4e49\u7ec4\u4ef6\u5185\u90e8\u9700\u8981\u7684 props<br \/>\n      const internalProps &#061; {<br \/>\n        class: &#039;my-component-base&#039;,<br \/>\n        style: { padding: &#039;1rem&#039;, border: &#039;1px solid #ccc&#039; },<br \/>\n        onClick: () &#061;&gt; {<br \/>\n          console.log(&#039;Internal click handler&#039;);<br \/>\n          \/\/ \u786e\u4fdd\u7528\u6237\u4f20\u5165\u7684 onClick \u4e5f\u88ab\u8c03\u7528<br \/>\n          props.onClick &amp;&amp; props.onClick();<br \/>\n        }<br \/>\n      };<\/p>\n<p>      \/\/ \u5408\u5e76\u5185\u90e8 props \u548c\u7528\u6237\u4f20\u5165\u7684 props<br \/>\n      \/\/ class \u548c style \u4f1a\u88ab\u5408\u5e76&#xff0c;onClick \u4f1a\u88ab\u5408\u5e76\u4e3a\u6570\u7ec4&#xff08;\u5982\u679c\u90fd\u5b58\u5728&#xff09;<br \/>\n      const mergedProps &#061; mergeProps(internalProps, {<br \/>\n        class: props.userClass, \/\/ \u5408\u5e76\u7c7b\u540d<br \/>\n        style: props.userStyle, \/\/ \u5408\u5e76\u6837\u5f0f\u5bf9\u8c61<br \/>\n        onClick: props.onClick \/\/ \u5408\u5e76\u4e8b\u4ef6\u5904\u7406\u5668<br \/>\n      });<\/p>\n<p>      return h(&#039;div&#039;, mergedProps, slots.default?.());<br \/>\n    };<br \/>\n  }<br \/>\n};\n<\/li>\n<li>\u4f18\u52bf&#xff1a;\n<ul>\n<li>\u5b89\u5168\u5408\u5e76&#xff1a;\u00a0\u907f\u514d\u624b\u52a8\u5408\u5e76\u00a0class\u00a0(\u5b57\u7b26\u4e32\u62fc\u63a5\u6613\u9519)\u3001style\u00a0(\u5bf9\u8c61\u5408\u5e76)\u3001\u4e8b\u4ef6\u5904\u7406\u5668&#xff08;\u6570\u7ec4&#xff09;\u7684\u590d\u6742\u6027\u548c\u9519\u8bef\u3002<\/li>\n<li>\u7ec4\u4ef6\u5c01\u88c5\u5229\u5668&#xff1a;\u00a0\u5728\u6784\u5efa\u53ef\u590d\u7528\u7ec4\u4ef6\u65f6&#xff0c;\u4f18\u96c5\u5730\u5c06\u5185\u90e8\u5b9e\u73b0\u7ec6\u8282\u4e0e\u7528\u6237\u81ea\u5b9a\u4e49\u914d\u7f6e\u7ed3\u5408\u3002<\/li>\n<li>\u9075\u5faa Vue \u89c4\u8303&#xff1a;\u00a0\u786e\u4fdd\u5408\u5e76\u884c\u4e3a\u4e0e Vue \u6a21\u677f\u4e2d\u7684\u00a0v-bind&#061;&#034;$attrs&#034;\u00a0\u548c\u00a0$attrs\u00a0\u7684\u5904\u7406\u65b9\u5f0f\u4e00\u81f4\u3002<\/li>\n<\/ul>\n<\/li>\n<li>JavaScript \u7c7b\u6bd4&#xff1a;\u00a0\u7c7b\u4f3c\u4e8e\u00a0Object.assign()&#xff0c;\u4f46\u529f\u80fd\u66f4\u5f3a\u5927\u4e14\u7406\u89e3 Vue \u7279\u5b9a\u7684\u5408\u5e76\u89c4\u5219\u3002\u4f60\u53ef\u4ee5\u628a\u5b83\u60f3\u8c61\u6210\u4e00\u4e2a\u667a\u80fd\u7684\u00a0Object.assign()&#xff0c;\u4e13\u95e8\u4e3a Vue \u7684 props \u8bbe\u8ba1&#xff0c;\u77e5\u9053\u00a0class\u00a0\u5e94\u8be5\u5408\u5e76\u5b57\u7b26\u4e32&#xff0c;style\u00a0\u5e94\u8be5\u6df1\u5ea6\u5408\u5e76\u5bf9\u8c61&#xff0c;\u4e8b\u4ef6\u76d1\u542c\u5668\u5e94\u8be5\u53d8\u6210\u6570\u7ec4\u3002<\/li>\n<\/ul>\n<hr \/>\n<h5>3.\u00a0cloneVNode()&#xff1a;VNode \u7684\u590d\u5236\u4e13\u5bb6<\/h5>\n<ul>\n<li>\u5b9a\u4e49&#xff1a;\u00a0cloneVNode()\u00a0\u51fd\u6570\u7528\u4e8e\u514b\u9686\u4e00\u4e2a\u73b0\u6709\u7684 VNode\u3002\u514b\u9686\u65f6\u53ef\u4ee5\u4f20\u5165\u65b0\u7684 props\u3001children \u6216 patchFlag \u6765\u4fee\u6539\u526f\u672c\u3002<\/li>\n<li>\u7528\u6cd5&#xff1a;\n<p>import { h, cloneVNode } from &#039;vue&#039;<\/p>\n<p>export default {<br \/>\n  setup(props, { slots }) {<br \/>\n    return () &#061;&gt; {<br \/>\n      \/\/ \u83b7\u53d6\u9ed8\u8ba4\u63d2\u69fd\u7684\u7b2c\u4e00\u4e2a VNode<br \/>\n      const defaultSlot &#061; slots.default?.();<br \/>\n      if (defaultSlot &amp;&amp; defaultSlot.length &gt; 0) {<br \/>\n        const firstVNode &#061; defaultSlot[0];<\/p>\n<p>        \/\/ \u514b\u9686\u7b2c\u4e00\u4e2a VNode&#xff0c;\u5e76\u6dfb\u52a0\u4e00\u4e2a\u65b0 class \u548c\u4fee\u6539 key<br \/>\n        const clonedVNode &#061; cloneVNode(firstVNode, {<br \/>\n          class: &#039;cloned-node&#039;, \/\/ \u65b0\u589e\u6216\u8986\u76d6 class<br \/>\n          key: &#039;cloned-&#039; &#043; firstVNode.key \/\/ \u4fee\u6539 key<br \/>\n          \/\/ \u6ce8\u610f&#xff1a;\u901a\u5e38\u4e0d\u76f4\u63a5\u4fee\u6539 children&#xff0c;\u9664\u975e\u660e\u786e\u9700\u8981<br \/>\n        });<\/p>\n<p>        return h(&#039;div&#039;, { class: &#039;wrapper&#039; }, [<br \/>\n          clonedVNode,<br \/>\n          \/\/ &#8230; \u5176\u4ed6\u5185\u5bb9<br \/>\n        ]);<br \/>\n      }<br \/>\n      return null;<br \/>\n    };<br \/>\n  }<br \/>\n};\n<\/li>\n<li>\u4f18\u52bf&#xff1a;\n<ul>\n<li>\u4e0d\u53ef\u53d8\u6027&#xff1a;\u00a0VNode \u662f\u4e0d\u53ef\u53d8\u7684\u3002cloneVNode()\u00a0\u662f\u4fee\u6539 VNode \u7684\u552f\u4e00\u5b89\u5168\u65b9\u5f0f&#xff08;\u901a\u8fc7\u521b\u5efa\u65b0\u526f\u672c&#xff09;\u3002<\/li>\n<li>\u9ad8\u9636\u7ec4\u4ef6 (HOC)&#xff1a;\u00a0\u5728 HOC \u4e2d\u975e\u5e38\u6709\u7528&#xff0c;\u53ef\u4ee5\u62e6\u622a\u3001\u4fee\u6539\u4f20\u5165\u7684 VNode&#xff08;\u5982\u6dfb\u52a0\u5305\u88c5\u3001\u4fee\u6539 props&#xff09;\u540e\u518d\u6e32\u67d3\u3002<\/li>\n<li>\u6761\u4ef6\u6e32\u67d3\/\u5305\u88c5&#xff1a;\u00a0\u52a8\u6001\u51b3\u5b9a\u662f\u5426\u5305\u88c5\u67d0\u4e2a\u5143\u7d20\u6216\u7ec4\u4ef6\u3002<\/li>\n<\/ul>\n<\/li>\n<li>JavaScript \u7c7b\u6bd4&#xff1a;\u00a0\u7c7b\u4f3c\u4e8e\u00a0Object.assign({}, originalObj, newProps)\u00a0\u6216\u4f7f\u7528\u5c55\u5f00\u8fd0\u7b97\u7b26\u00a0{&#8230;originalObj, &#8230;newProps}\u00a0\u6765\u521b\u5efa\u5bf9\u8c61\u7684\u6d45\u62f7\u8d1d\u5e76\u5408\u5e76\u65b0\u5c5e\u6027\u3002cloneVNode()\u00a0\u662f\u4e13\u95e8\u4e3a VNode \u5bf9\u8c61\u8bbe\u8ba1\u7684\u8fd9\u79cd\u201c\u514b\u9686\u5e76\u5408\u5e76\u201d\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<hr \/>\n<h5>4.\u00a0isVNode()&#xff1a;\u7c7b\u578b\u536b\u58eb<\/h5>\n<ul>\n<li>\u5b9a\u4e49&#xff1a;\u00a0isVNode()\u00a0\u51fd\u6570\u7528\u4e8e\u68c0\u67e5\u4e00\u4e2a\u503c\u662f\u5426\u4e3a\u6709\u6548\u7684 VNode \u5bf9\u8c61\u3002<\/li>\n<li>\u7528\u6cd5&#xff1a;\n<p>import { h, isVNode } from &#039;vue&#039;<\/p>\n<p>export default {<br \/>\n  setup(props, { slots }) {<br \/>\n    return () &#061;&gt; {<br \/>\n      const slotContent &#061; slots.default?.();<\/p>\n<p>      \/\/ \u5b89\u5168\u5730\u5904\u7406\u63d2\u69fd\u5185\u5bb9&#xff0c;\u53ef\u80fd\u5305\u542b\u6587\u672c\u3001VNode \u6570\u7ec4\u7b49<br \/>\n      const processedChildren &#061; (slotContent || []).map(child &#061;&gt; {<br \/>\n        if (isVNode(child)) {<br \/>\n          \/\/ \u5982\u679c\u662f VNode&#xff0c;\u53ef\u4ee5\u8fdb\u884c\u514b\u9686\u3001\u4fee\u6539\u7b49\u64cd\u4f5c<br \/>\n          return cloneVNode(child, { class: &#039;from-slot&#039; });<br \/>\n        } else {<br \/>\n          \/\/ \u5982\u679c\u662f\u5b57\u7b26\u4e32\u7b49\u539f\u59cb\u503c&#xff0c;\u76f4\u63a5\u8fd4\u56de\u6216\u5305\u88c5<br \/>\n          return h(&#039;span&#039;, { class: &#039;text-node&#039; }, child);<br \/>\n        }<br \/>\n      });<\/p>\n<p>      return h(&#039;div&#039;, { class: &#039;safe-wrapper&#039; }, processedChildren);<br \/>\n    };<br \/>\n  }<br \/>\n};\n<\/li>\n<li>\u4f18\u52bf&#xff1a;\n<ul>\n<li>\u7c7b\u578b\u5b89\u5168&#xff1a;\u00a0\u5728\u64cd\u4f5c\u53ef\u80fd\u4e3a VNode \u7684\u503c&#xff08;\u5982\u63d2\u69fd\u5185\u5bb9&#xff09;\u4e4b\u524d\u8fdb\u884c\u68c0\u67e5&#xff0c;\u907f\u514d\u8fd0\u884c\u65f6\u9519\u8bef\u3002<\/li>\n<li>\u6761\u4ef6\u903b\u8f91&#xff1a;\u00a0\u6839\u636e\u5185\u5bb9\u7c7b\u578b\u6267\u884c\u4e0d\u540c\u7684\u5904\u7406\u903b\u8f91\u3002<\/li>\n<\/ul>\n<\/li>\n<li>JavaScript \u7c7b\u6bd4&#xff1a;\u00a0\u7c7b\u4f3c\u4e8e\u00a0Array.isArray()\u00a0\u6216\u00a0typeof value &#061;&#061;&#061; &#039;object&#039;\u00a0\u8fd9\u6837\u7684\u7c7b\u578b\u68c0\u67e5\u51fd\u6570\u3002\u5b83\u544a\u8bc9\u4f60\u4e00\u4e2a\u503c\u662f\u5426\u5c5e\u4e8e\u7279\u5b9a\u7684\u201c\u7c7b\u578b\u201d&#xff08;\u8fd9\u91cc\u662f VNode&#xff09;\u3002<\/li>\n<\/ul>\n<hr \/>\n<h5>5.\u00a0resolveComponent()&#xff1a;\u7ec4\u4ef6\u7684\u52a8\u6001\u5b9a\u4f4d\u5668<\/h5>\n<ul>\n<li>\u5b9a\u4e49&#xff1a;\u00a0resolveComponent()\u00a0\u51fd\u6570\u7528\u4e8e\u6839\u636e\u7ec4\u4ef6\u7684\u6ce8\u518c\u540d\u79f0&#xff08;\u5b57\u7b26\u4e32&#xff09;\u52a8\u6001\u89e3\u6790\u51fa\u5bf9\u5e94\u7684\u7ec4\u4ef6\u5b9a\u4e49\u3002\u5b83\u4e3b\u8981\u5728\u5f53\u524d\u7ec4\u4ef6\u5b9e\u4f8b\u7684\u4e0a\u4e0b\u6587\u4e2d\u67e5\u627e&#xff08;\u901a\u8fc7\u00a0app.component()\u00a0\u6ce8\u518c\u6216\u5728\u00a0components\u00a0\u9009\u9879\u4e2d\u5b9a\u4e49&#xff09;\u3002<\/li>\n<li>\u7528\u6cd5&#xff1a;\n<p>import { h, resolveComponent } from &#039;vue&#039;<\/p>\n<p>export default {<br \/>\n  setup() {<br \/>\n    const componentName &#061; &#039;MyDynamicComponent&#039;; \/\/ \u53ef\u80fd\u6765\u81ea props \u6216\u8ba1\u7b97<\/p>\n<p>    return () &#061;&gt; {<br \/>\n      \/\/ \u52a8\u6001\u89e3\u6790\u7ec4\u4ef6<br \/>\n      const DynamicComponent &#061; resolveComponent(componentName);<\/p>\n<p>      \/\/ \u4f7f\u7528 h() \u521b\u5efa\u8be5\u7ec4\u4ef6\u7684 VNode<br \/>\n      \/\/ \u6ce8\u610f&#xff1a;\u5982\u679c\u7ec4\u4ef6\u672a\u6ce8\u518c&#xff0c;resolveComponent \u8fd4\u56de undefined<br \/>\n      if (DynamicComponent) {<br \/>\n        return h(DynamicComponent, { someProp: &#039;value&#039; });<br \/>\n      } else {<br \/>\n        return h(&#039;div&#039;, { style: { color: &#039;red&#039; } }, &#096;Component &#034;${componentName}&#034; not found!&#096;);<br \/>\n      }<br \/>\n    };<br \/>\n  }<br \/>\n};\n<\/li>\n<li>\u4f18\u52bf&#xff1a;\n<ul>\n<li>\u52a8\u6001\u7ec4\u4ef6&#xff1a;\u00a0\u5b9e\u73b0\u00a0&lt;component :is&#061;&#034;componentName&#034;&gt;\u00a0\u7684\u5e95\u5c42\u903b\u8f91&#xff0c;\u5141\u8bb8\u6839\u636e\u8fd0\u884c\u65f6\u6570\u636e\u51b3\u5b9a\u6e32\u67d3\u54ea\u4e2a\u7ec4\u4ef6\u3002<\/li>\n<li>\u63d2\u4ef6\/\u5e93\u5f00\u53d1&#xff1a;\u00a0\u6784\u5efa\u9700\u8981\u52a8\u6001\u52a0\u8f7d\u6216\u9009\u62e9\u7ec4\u4ef6\u7684\u529f\u80fd\u3002<\/li>\n<\/ul>\n<\/li>\n<li>JavaScript \u7c7b\u6bd4&#xff1a;\u00a0\u7c7b\u4f3c\u4e8e\u00a0window[variableName]\u00a0\u6216\u00a0obj[propertyName]\u00a0\u8fd9\u79cd\u52a8\u6001\u5c5e\u6027\u8bbf\u95ee\u3002\u4f60\u6709\u4e00\u4e2a\u5b57\u7b26\u4e32&#xff08;\u7ec4\u4ef6\u540d&#xff09;&#xff0c;\u60f3\u7528\u5b83\u6765\u83b7\u53d6\u4e00\u4e2a\u5b9e\u9645\u7684\u5bf9\u8c61&#xff08;\u7ec4\u4ef6\u5b9a\u4e49&#xff09;\u3002\u5b83\u50cf\u4e00\u4e2a\u6ce8\u518c\u8868\u67e5\u8be2\u5668\u3002<\/li>\n<\/ul>\n<hr \/>\n<h5>6.\u00a0resolveDirective()&#xff1a;\u6307\u4ee4\u7684\u52a8\u6001\u5b9a\u4f4d\u5668<\/h5>\n<ul>\n<li>\u5b9a\u4e49&#xff1a;\u00a0resolveDirective()\u00a0\u51fd\u6570\u7528\u4e8e\u6839\u636e\u6307\u4ee4\u7684\u6ce8\u518c\u540d\u79f0&#xff08;\u5b57\u7b26\u4e32&#xff09;\u52a8\u6001\u89e3\u6790\u51fa\u5bf9\u5e94\u7684\u6307\u4ee4\u5b9a\u4e49\u3002<\/li>\n<li>\u7528\u6cd5&#xff1a;\n<p>import { h, resolveDirective, withDirectives } from &#039;vue&#039;<\/p>\n<p>export default {<br \/>\n  setup() {<br \/>\n    const directiveName &#061; &#039;focus&#039;; \/\/ \u53ef\u80fd\u6765\u81ea\u914d\u7f6e<br \/>\n    const arg &#061; &#039;argValue&#039;;<br \/>\n    const modifiers &#061; { uppercase: true };<\/p>\n<p>    return () &#061;&gt; {<br \/>\n      \/\/ \u52a8\u6001\u89e3\u6790\u6307\u4ee4<br \/>\n      const directive &#061; resolveDirective(directiveName);<\/p>\n<p>      if (directive) {<br \/>\n        \/\/ \u9700\u8981\u4e0e withDirectives() \u914d\u5408\u4f7f\u7528<br \/>\n        const vnode &#061; h(&#039;input&#039;, { placeholder: &#039;Type here&#8230;&#039; });<br \/>\n        return withDirectives(vnode, [<br \/>\n          [directive, &#039;bindingValue&#039;, arg, modifiers] \/\/ [\u6307\u4ee4, \u503c, \u53c2\u6570, \u4fee\u9970\u7b26]<br \/>\n        ]);<br \/>\n      } else {<br \/>\n        return h(&#039;input&#039;, { placeholder: &#039;Directive not found&#039; });<br \/>\n      }<br \/>\n    };<br \/>\n  }<br \/>\n};\n<\/li>\n<li>\u4f18\u52bf&#xff1a;\n<ul>\n<li>\u52a8\u6001\u6307\u4ee4\u5e94\u7528&#xff1a;\u00a0\u5141\u8bb8\u5728\u8fd0\u884c\u65f6\u51b3\u5b9a\u7ed9\u5143\u7d20\u5e94\u7528\u54ea\u4e2a\u6307\u4ee4\u3002<\/li>\n<li>\u9ad8\u7ea7\u62bd\u8c61&#xff1a;\u00a0\u5728\u6784\u5efa\u9700\u8981\u52a8\u6001\u884c\u4e3a\u7684\u7ec4\u4ef6\u6216\u5de5\u5177\u65f6\u975e\u5e38\u6709\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<li>JavaScript \u7c7b\u6bd4&#xff1a;\u00a0\u4e0e\u00a0resolveComponent()\u00a0\u7c7b\u4f3c&#xff0c;\u4e5f\u662f\u52a8\u6001\u5c5e\u6027\u8bbf\u95ee\u6216\u6ce8\u518c\u8868\u67e5\u8be2&#xff0c;\u4f46\u76ee\u6807\u662f Vue \u6307\u4ee4\u3002<\/li>\n<\/ul>\n<hr \/>\n<h5>7.\u00a0withDirectives()&#xff1a;\u6307\u4ee4\u7684\u7ed1\u5b9a\u5668<\/h5>\n<ul>\n<li>\u5b9a\u4e49&#xff1a;\u00a0withDirectives()\u00a0\u51fd\u6570\u7528\u4e8e\u5c06\u4e00\u4e2a\u6216\u591a\u4e2a\u6307\u4ee4\u7ed1\u5b9a\u5230\u4e00\u4e2a VNode \u4e0a\u3002\u5b83\u63a5\u6536\u4e00\u4e2a VNode \u548c\u4e00\u4e2a\u6307\u4ee4\u7ed1\u5b9a\u6570\u7ec4\u4f5c\u4e3a\u53c2\u6570&#xff0c;\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684&#xff08;\u514b\u9686\u7684&#xff09;VNode\u3002<\/li>\n<li>\u7528\u6cd5&#xff1a;\u00a0(\u89c1\u00a0resolveDirective()\u00a0\u793a\u4f8b)\n<p>\/\/ &#8230; (\u5728 resolveDirective \u793a\u4f8b\u4e2d\u5df2\u5c55\u793a)<br \/>\nconst vnode &#061; h(&#039;p&#039;, &#039;Hello&#039;);<br \/>\nconst vnodeWithDirectives &#061; withDirectives(vnode, [<br \/>\n  [vShow, isVisible], \/\/ \u7ed1\u5b9a v-show \u6307\u4ee4<br \/>\n  [vMyCustom, &#039;value&#039;, &#039;arg&#039;, { mod1: true, mod2: false }] \/\/ \u7ed1\u5b9a\u81ea\u5b9a\u4e49\u6307\u4ee4<br \/>\n]);<br \/>\nreturn vnodeWithDirectives;\n<\/li>\n<li>\u4f18\u52bf&#xff1a;\n<ul>\n<li>\u7a0b\u5e8f\u5316\u5e94\u7528\u6307\u4ee4&#xff1a;\u00a0\u5728\u6e32\u67d3\u51fd\u6570\u4e2d\u4e3a VNode \u6dfb\u52a0\u6307\u4ee4&#xff0c;\u8fd9\u662f\u00a0&lt;template&gt;\u00a0\u65e0\u6cd5\u76f4\u63a5\u505a\u5230\u7684&#xff08;&lt;template&gt;\u00a0\u4e2d\u6307\u4ee4\u662f\u9759\u6001\u5199\u5165\u7684&#xff09;\u3002<\/li>\n<li>\u4e0e\u00a0resolveDirective()\u00a0\u914d\u5408&#xff1a;\u00a0\u5b9e\u73b0\u52a8\u6001\u6307\u4ee4\u7ed1\u5b9a\u3002<\/li>\n<\/ul>\n<\/li>\n<li>JavaScript \u7c7b\u6bd4&#xff1a;\u00a0\u7c7b\u4f3c\u4e8e\u00a0element.setAttribute(&#039;data-directive&#039;, value)&#xff0c;\u4f46\u5b83\u662f\u4e3a Vue \u7684\u6307\u4ee4\u7cfb\u7edf\u8bbe\u8ba1\u7684&#xff0c;\u80fd\u5904\u7406\u590d\u6742\u7684\u7ed1\u5b9a&#xff08;\u503c\u3001\u53c2\u6570\u3001\u4fee\u9970\u7b26&#xff09;\u5e76\u786e\u4fdd\u6307\u4ee4\u7684\u751f\u547d\u5468\u671f\u94a9\u5b50\u88ab\u6b63\u786e\u8c03\u7528\u3002\u53ef\u4ee5\u770b\u4f5c\u662f\u4e3a VNode \u6dfb\u52a0\u7279\u6b8a\u5143\u6570\u636e&#xff08;\u6307\u4ee4\u7ed1\u5b9a&#xff09;\u7684\u51fd\u6570\u3002<\/li>\n<\/ul>\n<hr \/>\n<h5>8.\u00a0withModifiers()&#xff1a;\u4e8b\u4ef6\u4fee\u9970\u7b26\u7684\u751f\u6210\u5668<\/h5>\n<ul>\n<li>\u5b9a\u4e49&#xff1a;\u00a0withModifiers()\u00a0\u51fd\u6570\u7528\u4e8e\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4e8b\u4ef6\u4fee\u9970\u7b26\u529f\u80fd\u7684\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u5305\u88c5\u5668\u3002\u5b83\u672c\u8eab\u4e0d\u76f4\u63a5\u4fee\u6539 VNode&#xff0c;\u800c\u662f\u4fee\u6539\u4e8b\u4ef6\u5904\u7406\u5668\u51fd\u6570\u3002<\/li>\n<li>\u7528\u6cd5&#xff1a;\n<p>import { h, withModifiers } from &#039;vue&#039;<\/p>\n<p>export default {<br \/>\n  setup() {<br \/>\n    const clickHandler &#061; (event) &#061;&gt; {<br \/>\n      console.log(&#039;Clicked!&#039;, event);<br \/>\n    };<\/p>\n<p>    return () &#061;&gt; {<br \/>\n      return h(&#039;div&#039;, [<br \/>\n        \/\/ .self \u4fee\u9970\u7b26&#xff1a;\u53ea\u6709\u4e8b\u4ef6.target \u662f\u5143\u7d20\u672c\u8eab\u65f6\u624d\u89e6\u53d1<br \/>\n        h(&#039;button&#039;, {<br \/>\n          onClick: withModifiers(clickHandler, [&#039;self&#039;])<br \/>\n        }, &#039;Click (self)&#039;),<\/p>\n<p>        \/\/ .prevent \u4fee\u9970\u7b26&#xff1a;\u8c03\u7528 event.preventDefault()<br \/>\n        h(&#039;a&#039;, {<br \/>\n          href: &#039;https:\/\/example.com&#039;,<br \/>\n          onClick: withModifiers(clickHandler, [&#039;prevent&#039;])<br \/>\n        }, &#039;Link (prevent)&#039;),<\/p>\n<p>        \/\/ .stop \u4fee\u9970\u7b26&#xff1a;\u8c03\u7528 event.stopPropagation()<br \/>\n        h(&#039;div&#039;, {<br \/>\n          onClick: () &#061;&gt; console.log(&#039;Outer div clicked&#039;)<br \/>\n        }, [<br \/>\n          h(&#039;button&#039;, {<br \/>\n            onClick: withModifiers(clickHandler, [&#039;stop&#039;])<br \/>\n          }, &#039;Button (stop)&#039;)<br \/>\n        ])<br \/>\n      ]);<br \/>\n    };<br \/>\n  }<br \/>\n};\n<\/li>\n<li>\u4f18\u52bf&#xff1a;\n<ul>\n<li>\u7a0b\u5e8f\u5316\u4e8b\u4ef6\u4fee\u9970\u7b26&#xff1a;\u00a0\u5728 JavaScript \u4e2d\u52a8\u6001\u5e94\u7528\u00a0.stop,\u00a0.prevent,\u00a0.self,\u00a0.once,\u00a0.capture,\u00a0.passive,\u00a0.trim,\u00a0.number\u00a0\u7b49\u4fee\u9970\u7b26\u3002<\/li>\n<li>\u6e05\u6670\u7684\u903b\u8f91&#xff1a;\u00a0\u5c06\u4fee\u9970\u7b26\u903b\u8f91\u5c01\u88c5\u5728\u51fd\u6570\u5185\u90e8&#xff0c;\u4fdd\u6301\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u7684\u7eaf\u51c0\u3002<\/li>\n<\/ul>\n<\/li>\n<li>JavaScript \u7c7b\u6bd4&#xff1a;\u00a0\u8fd9\u662f\u4e00\u4e2a\u9ad8\u9636\u51fd\u6570 (Higher-Order Function &#8211; HOF)\u3002\u5b83\u63a5\u6536\u4e00\u4e2a\u51fd\u6570&#xff08;\u4e8b\u4ef6\u5904\u7406\u5668&#xff09;\u548c\u4e00\u4e9b\u914d\u7f6e&#xff08;\u4fee\u9970\u7b26&#xff09;&#xff0c;\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u51fd\u6570&#xff0c;\u8fd9\u4e2a\u65b0\u51fd\u6570\u5728\u8c03\u7528\u539f\u59cb\u51fd\u6570\u4e4b\u524d\u4f1a\u6267\u884c\u4fee\u9970\u7b26\u6307\u5b9a\u7684\u64cd\u4f5c&#xff08;\u5982\u00a0event.stopPropagation()&#xff09;\u3002\u7c7b\u4f3c\u4e8e\u00a0_.throttle()\u00a0\u6216\u00a0_.debounce()\u00a0\u8fd9\u6837\u7684\u51fd\u6570\u5305\u88c5\u5668\u3002<\/li>\n<\/ul>\n<hr \/>\n<h5>\u603b\u7ed3\u4e0e\u6700\u4f73\u5b9e\u8df5<\/h5>\n<table>\n<tr>API\u6838\u5fc3\u4f5c\u7528JavaScript \u7c7b\u6bd4<\/tr>\n<tbody>\n<tr>\n<td>h()<\/td>\n<td>\u521b\u5efa VNode<\/td>\n<td>document.createElement\u00a0&#043;\u00a0setAttribute\u00a0&#043;\u00a0appendChild\u00a0(\u5de5\u5382\u51fd\u6570)<\/td>\n<\/tr>\n<tr>\n<td>mergeProps()<\/td>\n<td>\u667a\u80fd\u5408\u5e76 Props<\/td>\n<td>\u667a\u80fd\u7684\u00a0Object.assign()\u00a0(\u7406\u89e3 Vue \u5408\u5e76\u89c4\u5219)<\/td>\n<\/tr>\n<tr>\n<td>cloneVNode()<\/td>\n<td>\u514b\u9686\u5e76\u53ef\u9009\u4fee\u6539 VNode<\/td>\n<td>{&#8230;originalVNode, &#8230;newProps}\u00a0(\u5bf9\u8c61\u514b\u9686\u4e0e\u5408\u5e76)<\/td>\n<\/tr>\n<tr>\n<td>isVNode()<\/td>\n<td>\u68c0\u67e5\u662f\u5426\u4e3a VNode<\/td>\n<td>Array.isArray()\u00a0(\u7c7b\u578b\u68c0\u67e5)<\/td>\n<\/tr>\n<tr>\n<td>resolveComponent()<\/td>\n<td>\u6309\u540d\u89e3\u6790\u7ec4\u4ef6<\/td>\n<td>obj[componentName]\u00a0(\u52a8\u6001\u5c5e\u6027\u8bbf\u95ee\/\u6ce8\u518c\u8868\u67e5\u8be2)<\/td>\n<\/tr>\n<tr>\n<td>resolveDirective()<\/td>\n<td>\u6309\u540d\u89e3\u6790\u6307\u4ee4<\/td>\n<td>obj[directiveName]\u00a0(\u52a8\u6001\u5c5e\u6027\u8bbf\u95ee\/\u6ce8\u518c\u8868\u67e5\u8be2)<\/td>\n<\/tr>\n<tr>\n<td>withDirectives()<\/td>\n<td>\u4e3a VNode \u7ed1\u5b9a\u6307\u4ee4<\/td>\n<td>element.setAttribute()\u00a0(\u4e3a VNode \u6dfb\u52a0\u5143\u6570\u636e)<\/td>\n<\/tr>\n<tr>\n<td>withModifiers()<\/td>\n<td>\u4e3a\u4e8b\u4ef6\u5904\u7406\u5668\u6dfb\u52a0\u4fee\u9970\u7b26<\/td>\n<td>\u9ad8\u9636\u51fd\u6570 (HOF)&#xff0c;\u5982\u00a0_.throttle()\u00a0(\u51fd\u6570\u5305\u88c5\u5668)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4f55\u65f6\u4f7f\u7528\u6e32\u67d3\u51fd\u6570&#xff1f;<\/p>\n<ul>\n<li>\u52a8\u6001\u6027\u9700\u6c42\u9ad8&#xff1a;\u00a0\u7ec4\u4ef6\u3001\u6307\u4ee4\u3001\u7ed3\u6784\u9700\u8981\u6839\u636e\u590d\u6742\u903b\u8f91\u52a8\u6001\u51b3\u5b9a\u3002<\/li>\n<li>\u6784\u5efa\u9ad8\u7ea7\u62bd\u8c61&#xff1a;\u00a0\u5f00\u53d1 UI \u5e93\u3001\u9ad8\u9636\u7ec4\u4ef6 (HOC)\u3001\u5e03\u5c40\u7cfb\u7edf\u3001\u8868\u5355\u751f\u6210\u5668\u7b49\u3002<\/li>\n<li>\u6027\u80fd\u5173\u952e\u4e14\u9700\u8981\u7cbe\u7ec6\u63a7\u5236&#xff1a;\u00a0\u867d\u7136\u00a0&lt;template&gt;\u00a0\u7f16\u8bd1\u540e\u6027\u80fd\u5f88\u597d&#xff0c;\u4f46\u5728\u6781\u5c11\u6570\u9700\u8981\u6781\u81f4\u4f18\u5316\u7684\u573a\u666f&#xff0c;\u76f4\u63a5\u64cd\u4f5c VNode \u53ef\u80fd\u63d0\u4f9b\u66f4\u76f4\u63a5\u7684\u63a7\u5236&#xff08;\u4f46\u901a\u5e38\u4e0d\u63a8\u8350&#xff0c;\u9664\u975e\u6709\u660e\u786e\u8bc1\u636e&#xff09;\u3002<\/li>\n<li>\u4e0e JSX \u914d\u5408&#xff1a;\u00a0\u5982\u679c\u4f60\u5728 Vue \u9879\u76ee\u4e2d\u4f7f\u7528 JSX&#xff0c;\u8fd9\u4e9b API \u662f\u5e95\u5c42\u652f\u6491\u3002<\/li>\n<\/ul>\n<p>\u6ce8\u610f\u4e8b\u9879&#xff1a;<\/p>\n<li>\u5b66\u4e60\u66f2\u7ebf&#xff1a;\u00a0\u6e32\u67d3\u51fd\u6570\u6bd4\u00a0&lt;template&gt;\u00a0\u66f4\u590d\u6742&#xff0c;\u9700\u8981\u7406\u89e3 VNode \u6982\u5ff5\u3002<\/li>\n<li>\u53ef\u8bfb\u6027&#xff1a;\u00a0\u590d\u6742\u7684 UI \u7528\u00a0h()\u00a0\u5199\u53ef\u80fd\u4e0d\u5982\u00a0&lt;template&gt;\u00a0\u76f4\u89c2\u3002<\/li>\n<li>\u5de5\u5177\u652f\u6301&#xff1a;\u00a0&lt;template&gt;\u00a0\u6709\u66f4\u6210\u719f\u7684 IDE \u652f\u6301&#xff08;\u8bed\u6cd5\u9ad8\u4eae\u3001\u9519\u8bef\u68c0\u67e5&#xff09;\u3002<\/li>\n<li>$attrs\u00a0\u548c\u00a0$slots&#xff1a;\u00a0\u5728\u6e32\u67d3\u51fd\u6570\u4e2d&#xff0c;setup()\u00a0\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u00a0{ attrs, slots }\u00a0\u63d0\u4f9b\u4e86\u5bf9\u00a0$attrs\u00a0\u548c\u00a0$slots\u00a0\u7684\u8bbf\u95ee&#xff0c;\u5b83\u4eec\u662f\u666e\u901a\u5bf9\u8c61\u548c\u51fd\u6570&#xff0c;\u4f7f\u7528\u65b9\u5f0f\u4e0e\u00a0&lt;template&gt;\u00a0\u4e2d\u7c7b\u4f3c\u3002<\/li>\n<p>\u7ed3\u8bed<\/p>\n<p>Vue 3 \u7684\u6e32\u67d3\u51fd\u6570 API \u63d0\u4f9b\u4e86\u8d85\u8d8a &lt;template&gt; \u7684\u5f3a\u5927\u80fd\u529b\u548c\u7075\u6d3b\u6027\u3002\u638c\u63e1 h(), mergeProps(), cloneVNode() \u7b49\u5de5\u5177&#xff0c;\u8ba9\u4f60\u80fd\u591f\u6784\u5efa\u66f4\u52a8\u6001\u3001\u66f4\u62bd\u8c61\u3001\u66f4\u5f3a\u5927\u7684 Vue \u5e94\u7528\u548c\u7ec4\u4ef6\u5e93\u3002\u7406\u89e3\u5b83\u4eec\u4e0e JavaScript \u539f\u751f\u6982\u5ff5\u7684\u7c7b\u6bd4&#xff0c;\u6709\u52a9\u4e8e\u66f4\u5feb\u5730\u638c\u63e1\u5176\u7cbe\u9ad3\u3002\u5728\u5408\u9002\u7684\u573a\u666f\u4e0b\u8fd0\u7528\u8fd9\u4e9b\u6b66\u5668&#xff0c;\u4f60\u7684 Vue \u5f00\u53d1\u80fd\u529b\u5c06\u66f4\u4e0a\u4e00\u5c42\u697c&#xff01;<\/p>\n<p>\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u5bf9\u4f60\u6709\u5e2e\u52a9&#xff01;\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u4ea4\u6d41\u8ba8\u8bba\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb905\u6b21\uff0c\u70b9\u8d5e7\u6b21\uff0c\u6536\u85cf24\u6b21\u3002\u672c\u6587\u6df1\u5165\u89e3\u6790Vue3\u4e2d8\u4e2a\u6838\u5fc3\u6e32\u67d3\u51fd\u6570API\uff1ah()\u7528\u4e8e\u521b\u5efaVNode\uff0cmergeProps()\u667a\u80fd\u5408\u5e76props\uff0ccloneVNode()\u514b\u9686VNode\uff0cisVNode()\u7c7b\u578b\u68c0\u67e5\uff0cresolveComponent()\/resolveDirective()\u52a8\u6001\u89e3\u6790\u7ec4\u4ef6\u548c\u6307\u4ee4\uff0cwithDirectives()\u7ed1\u5b9a\u6307\u4ee4\uff0cwithModifiers()\u5904\u7406\u4e8b\u4ef6\u4fee\u9970\u7b26\u3002\u8fd9\u4e9bAPI\u63d0\u4f9b\u4e86\u6bd4\u6a21\u677f\u66f4\u5f3a\u5927\u7684\u52a8\u6001UI\u6784\u5efa\u80fd\u529b\uff0c\u7279\u522b\u9002\u5408\u5f00\u53d1\u9ad8\u7ea7\u7ec4\u4ef6\u3001UI\u5e93\u548c\u9700\u8981\u590d\u6742\u903b\u8f91\u7684\u573a\u666f\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[187,6084,625,87],"topic":[],"class_list":["post-57858","post","type-post","status-publish","format-standard","hentry","category-server","tag-javascript","tag-jsx","tag-vue-js","tag-87"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Vue 3 \u6e32\u67d3\u51fd\u6570\u8fdb\u9636\u6307\u5357\uff1ah(), mergeProps(), cloneVNode() \u7b49\u6838\u5fc3 API \u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/57858.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Vue 3 \u6e32\u67d3\u51fd\u6570\u8fdb\u9636\u6307\u5357\uff1ah(), mergeProps(), cloneVNode() \u7b49\u6838\u5fc3 API \u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb905\u6b21\uff0c\u70b9\u8d5e7\u6b21\uff0c\u6536\u85cf24\u6b21\u3002\u672c\u6587\u6df1\u5165\u89e3\u6790Vue3\u4e2d8\u4e2a\u6838\u5fc3\u6e32\u67d3\u51fd\u6570API\uff1ah()\u7528\u4e8e\u521b\u5efaVNode\uff0cmergeProps()\u667a\u80fd\u5408\u5e76props\uff0ccloneVNode()\u514b\u9686VNode\uff0cisVNode()\u7c7b\u578b\u68c0\u67e5\uff0cresolveComponent()\/resolveDirective()\u52a8\u6001\u89e3\u6790\u7ec4\u4ef6\u548c\u6307\u4ee4\uff0cwithDirectives()\u7ed1\u5b9a\u6307\u4ee4\uff0cwithModifiers()\u5904\u7406\u4e8b\u4ef6\u4fee\u9970\u7b26\u3002\u8fd9\u4e9bAPI\u63d0\u4f9b\u4e86\u6bd4\u6a21\u677f\u66f4\u5f3a\u5927\u7684\u52a8\u6001UI\u6784\u5efa\u80fd\u529b\uff0c\u7279\u522b\u9002\u5408\u5f00\u53d1\u9ad8\u7ea7\u7ec4\u4ef6\u3001UI\u5e93\u548c\u9700\u8981\u590d\u6742\u903b\u8f91\u7684\u573a\u666f\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/57858.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-15T13:19:59+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/57858.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/57858.html\",\"name\":\"Vue 3 \u6e32\u67d3\u51fd\u6570\u8fdb\u9636\u6307\u5357\uff1ah(), mergeProps(), cloneVNode() \u7b49\u6838\u5fc3 API \u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-15T13:19:59+00:00\",\"dateModified\":\"2025-08-15T13:19:59+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/57858.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/57858.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/57858.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Vue 3 \u6e32\u67d3\u51fd\u6570\u8fdb\u9636\u6307\u5357\uff1ah(), mergeProps(), cloneVNode() \u7b49\u6838\u5fc3 API \u6df1\u5ea6\u89e3\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Vue 3 \u6e32\u67d3\u51fd\u6570\u8fdb\u9636\u6307\u5357\uff1ah(), mergeProps(), cloneVNode() \u7b49\u6838\u5fc3 API \u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/57858.html","og_locale":"zh_CN","og_type":"article","og_title":"Vue 3 \u6e32\u67d3\u51fd\u6570\u8fdb\u9636\u6307\u5357\uff1ah(), mergeProps(), cloneVNode() \u7b49\u6838\u5fc3 API \u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb905\u6b21\uff0c\u70b9\u8d5e7\u6b21\uff0c\u6536\u85cf24\u6b21\u3002\u672c\u6587\u6df1\u5165\u89e3\u6790Vue3\u4e2d8\u4e2a\u6838\u5fc3\u6e32\u67d3\u51fd\u6570API\uff1ah()\u7528\u4e8e\u521b\u5efaVNode\uff0cmergeProps()\u667a\u80fd\u5408\u5e76props\uff0ccloneVNode()\u514b\u9686VNode\uff0cisVNode()\u7c7b\u578b\u68c0\u67e5\uff0cresolveComponent()\/resolveDirective()\u52a8\u6001\u89e3\u6790\u7ec4\u4ef6\u548c\u6307\u4ee4\uff0cwithDirectives()\u7ed1\u5b9a\u6307\u4ee4\uff0cwithModifiers()\u5904\u7406\u4e8b\u4ef6\u4fee\u9970\u7b26\u3002\u8fd9\u4e9bAPI\u63d0\u4f9b\u4e86\u6bd4\u6a21\u677f\u66f4\u5f3a\u5927\u7684\u52a8\u6001UI\u6784\u5efa\u80fd\u529b\uff0c\u7279\u522b\u9002\u5408\u5f00\u53d1\u9ad8\u7ea7\u7ec4\u4ef6\u3001UI\u5e93\u548c\u9700\u8981\u590d\u6742\u903b\u8f91\u7684\u573a\u666f\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/57858.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-15T13:19:59+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/57858.html","url":"https:\/\/www.wsisp.com\/helps\/57858.html","name":"Vue 3 \u6e32\u67d3\u51fd\u6570\u8fdb\u9636\u6307\u5357\uff1ah(), mergeProps(), cloneVNode() \u7b49\u6838\u5fc3 API \u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-15T13:19:59+00:00","dateModified":"2025-08-15T13:19:59+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/57858.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/57858.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/57858.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Vue 3 \u6e32\u67d3\u51fd\u6570\u8fdb\u9636\u6307\u5357\uff1ah(), mergeProps(), cloneVNode() \u7b49\u6838\u5fc3 API \u6df1\u5ea6\u89e3\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/57858","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=57858"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/57858\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=57858"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=57858"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=57858"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=57858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}