{"id":65,"date":"2022-05-29T12:49:57","date_gmt":"2022-05-29T04:49:57","guid":{"rendered":"http:\/\/www.33weixin.com\/index\/?p=65"},"modified":"2022-05-29T12:51:51","modified_gmt":"2022-05-29T04:51:51","slug":"render-%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"http:\/\/www.33weixin.com\/index\/index.php\/2022\/05\/29\/render-%e5%87%bd%e6%95%b0\/","title":{"rendered":"Render \u51fd\u6570"},"content":{"rendered":"<h2 id=\"\u57fa\u7840\">\u57fa\u7840<\/h2>\n<p>Vue \u63a8\u8350\u4f7f\u7528\u5728\u7edd\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u4f7f\u7528 template \u6765\u521b\u5efa\u4f60\u7684 HTML\u3002\u7136\u800c\u5728\u4e00\u4e9b\u573a\u666f\u4e2d\uff0c\u4f60\u771f\u7684\u9700\u8981 JavaScript \u7684\u5b8c\u5168\u7f16\u7a0b\u7684\u80fd\u529b\uff0c\u8fd9\u5c31\u662f\u00a0<strong>render \u51fd\u6570<\/strong>\uff0c\u5b83\u6bd4 template \u66f4\u63a5\u8fd1\u7f16\u8bd1\u5668\u3002<\/p>\n<pre><code class=\"lang-html\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h1<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">a<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"hello-world\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"#hello-world\"<\/span>&gt;<\/span>\n    Hello world!\n  <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">a<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h1<\/span>&gt;<\/span>\n<\/code><\/pre>\n<p>\u5728 HTML \u5c42\uff0c \u6211\u4eec\u51b3\u5b9a\u8fd9\u6837\u5b9a\u4e49\u7ec4\u4ef6\u63a5\u53e3\uff1a<\/p>\n<pre><code class=\"lang-html\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">anchored-heading<\/span> <span class=\"hljs-attr\">:level<\/span>=<span class=\"hljs-string\">\"1\"<\/span>&gt;<\/span>Hello world!<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">anchored-heading<\/span>&gt;<\/span>\n<\/code><\/pre>\n<p>\u5f53\u6211\u4eec\u5f00\u59cb\u5199\u4e00\u4e2a\u901a\u8fc7\u00a0<code>level<\/code>\u00a0prop \u52a8\u6001\u751f\u6210heading \u6807\u7b7e\u7684\u7ec4\u4ef6\uff0c\u4f60\u53ef\u5f88\u5feb\u80fd\u60f3\u5230\u8fd9\u6837\u5b9e\u73b0\uff1a<\/p>\n<pre><code class=\"lang-html\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">script<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"text\/x-template\"<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"anchored-heading-template\"<\/span>&gt;<\/span><span class=\"handlebars\"><span class=\"xml\">\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h1<\/span> <span class=\"hljs-attr\">v-if<\/span>=<span class=\"hljs-string\">\"level === 1\"<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">slot<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">slot<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h1<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h2<\/span> <span class=\"hljs-attr\">v-if<\/span>=<span class=\"hljs-string\">\"level === 2\"<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">slot<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">slot<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h2<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h3<\/span> <span class=\"hljs-attr\">v-if<\/span>=<span class=\"hljs-string\">\"level === 3\"<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">slot<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">slot<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h3<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h4<\/span> <span class=\"hljs-attr\">v-if<\/span>=<span class=\"hljs-string\">\"level === 4\"<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">slot<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">slot<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h4<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h5<\/span> <span class=\"hljs-attr\">v-if<\/span>=<span class=\"hljs-string\">\"level === 5\"<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">slot<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">slot<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h5<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h6<\/span> <span class=\"hljs-attr\">v-if<\/span>=<span class=\"hljs-string\">\"level === 6\"<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">slot<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">slot<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h6<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n<\/span><\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">script<\/span>&gt;<\/span>\n<\/code><\/pre>\n<pre><code class=\"lang-js\">Vue.component(<span class=\"hljs-string\">'anchored-heading'<\/span>, {\n  template: <span class=\"hljs-string\">'#anchored-heading-template'<\/span>,\n  props: {\n    level: {\n      type: <span class=\"hljs-built_in\">Number<\/span>,\n      required: <span class=\"hljs-literal\">true<\/span>\n    }\n  }\n})\n<\/code><\/pre>\n<p>template \u5728\u8fd9\u79cd\u573a\u666f\u4e2d\u5c31\u8868\u73b0\u7684\u6709\u4e9b\u5197\u4f59\u4e86\u3002\u867d\u7136\u6211\u4eec\u91cd\u590d\u4f7f\u7528\u00a0<code>&lt;slot&gt;&lt;\/slot&gt;<\/code>\u00a0\u6765\u63a5\u6536\u6bcf\u4e00\u4e2a\u7ea7\u522b\u7684\u6807\u9898\u6807\u7b7e\uff0c\u5728\u6807\u9898\u6807\u7b7e\u4e2d\u6dfb\u52a0\u76f8\u540c\u7684\u951a\u70b9\u5143\u7d20\u3002\u4f46\u662f\u4e9b\u90fd\u4f1a\u88ab\u5305\u88f9\u5728\u4e00\u4e2a\u65e0\u7528\u7684\u00a0<code>div<\/code>\u00a0\u4e2d\uff0c\u56e0\u4e3a\u7ec4\u4ef6\u5fc5\u987b\u6709\u6839\u8282\u70b9\u3002<\/p>\n<p>\u867d\u7136\u6a21\u677f\u5728\u5927\u591a\u6570\u7ec4\u4ef6\u4e2d\u90fd\u975e\u5e38\u597d\u7528\uff0c\u4f46\u662f\u5728\u8fd9\u91cc\u5b83\u5c31\u4e0d\u662f\u5f88\u7b80\u6d01\u7684\u4e86\u3002\u90a3\u4e48\uff0c\u6211\u4eec\u6765\u5c1d\u8bd5\u4f7f\u7528\u00a0<code>render<\/code>\u00a0\u51fd\u6570\u91cd\u5199\u4e0a\u9762\u7684\u4f8b\u5b50\uff1a<\/p>\n<pre><code class=\"lang-js\">Vue.component(<span class=\"hljs-string\">'anchored-heading'<\/span>, {\n  render: <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">createElement<\/span>) <\/span>{\n    <span class=\"hljs-keyword\">return<\/span> createElement(\n      <span class=\"hljs-string\">'h'<\/span> + <span class=\"hljs-keyword\">this<\/span>.level,   <span class=\"hljs-comment\">\/\/ tag name \u6807\u7b7e\u540d\u79f0<\/span>\n      <span class=\"hljs-keyword\">this<\/span>.$slots.default <span class=\"hljs-comment\">\/\/ \u5b50\u7ec4\u4ef6\u4e2d\u7684\u9635\u5217<\/span>\n    )\n  },\n  props: {\n    level: {\n      type: <span class=\"hljs-built_in\">Number<\/span>,\n      required: <span class=\"hljs-literal\">true<\/span>\n    }\n  }\n})\n<\/code><\/pre>\n<p>\u7b80\u5355\u6e05\u6670\u5f88\u591a\uff01\u7b80\u5355\u6765\u8bf4\uff0c\u8fd9\u6837\u4ee3\u7801\u7cbe\u7b80\u5f88\u591a\uff0c\u4f46\u662f\u9700\u8981\u975e\u5e38\u719f\u6089 Vue \u7684\u5b9e\u4f8b\u5c5e\u6027\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4f60\u9700\u8981\u77e5\u9053\u5f53\u4f60\u4e0d\u4f7f\u7528\u00a0<code>slot<\/code>\u00a0\u5c5e\u6027\u5411\u7ec4\u4ef6\u4e2d\u4f20\u9012\u5185\u5bb9\u65f6\uff0c\u6bd4\u5982\u00a0<code>anchored-heading<\/code>\u00a0\u4e2d\u7684\u00a0<code>Hello world!<\/code>, \u8fd9\u4e9b\u5b50\u5143\u7d20\u88ab\u5b58\u50a8\u5728\u7ec4\u4ef6\u5b9e\u4f8b\u4e2d\u7684\u00a0<code>$slots.default<\/code>\u4e2d\u3002\u5982\u679c\u4f60\u8fd8\u4e0d\u4e86\u89e3\uff0c<strong>\u00a0\u5728\u6df1\u5165 render \u51fd\u6570\u4e4b\u524d\u63a8\u8350\u9605\u8bfb\u00a0<a href=\"http:\/\/caibaojian.com\/vue\/api#vm-slots\">instance properties API<\/a>\u3002<\/strong><\/p>\n<h2 id=\"createelement-\u53c2\u6570\"><code>createElement<\/code>\u00a0\u53c2\u6570<\/h2>\n<p>\u7b2c\u4e8c\u4ef6\u4f60\u9700\u8981\u719f\u6089\u7684\u662f\u5982\u4f55\u5728\u00a0<code>createElement<\/code>\u00a0\u51fd\u6570\u4e2d\u751f\u6210\u6a21\u677f\u3002\u8fd9\u91cc\u662f\u00a0<code>createElement<\/code>\u00a0\u63a5\u53d7\u7684\u53c2\u6570\uff1a<\/p>\n<pre><code class=\"lang-js\"><span class=\"hljs-comment\">\/\/ @returns {VNode}<\/span>\ncreateElement(\n  <span class=\"hljs-comment\">\/\/ {String | Object | Function}<\/span>\n  <span class=\"hljs-comment\">\/\/ \u4e00\u4e2a HTML \u6807\u7b7e\uff0c\u7ec4\u4ef6\u8bbe\u7f6e\uff0c\u6216\u4e00\u4e2a\u51fd\u6570<\/span>\n  <span class=\"hljs-comment\">\/\/ \u5fc5\u987b Return \u4e0a\u8ff0\u5176\u4e2d\u4e00\u4e2a<\/span>\n  <span class=\"hljs-string\">'div'<\/span>,\n\n  <span class=\"hljs-comment\">\/\/ {Object}<\/span>\n  <span class=\"hljs-comment\">\/\/ \u4e00\u4e2a\u5bf9\u5e94\u5c5e\u6027\u7684\u6570\u636e\u5bf9\u8c61<\/span>\n  <span class=\"hljs-comment\">\/\/ \u60a8\u53ef\u4ee5\u5728 template \u4e2d\u4f7f\u7528.\u53ef\u9009\u9879.<\/span>\n  {\n    <span class=\"hljs-comment\">\/\/ (\u4e0b\u4e00\u7ae0\uff0c\u5c06\u8be6\u7ec6\u8bf4\u660e\u76f8\u5173\u7ec6\u8282)<\/span>\n  },\n\n  <span class=\"hljs-comment\">\/\/ {String | Array}<\/span>\n  <span class=\"hljs-comment\">\/\/ \u5b50\u8282\u70b9(VNodes). \u53ef\u9009\u9879.<\/span>\n  [\n    createElement(<span class=\"hljs-string\">'h1'<\/span>, <span class=\"hljs-string\">'hello world'<\/span>),\n    createElement(MyComponent, {\n      props: {\n        someProp: <span class=\"hljs-string\">'foo'<\/span>\n      }\n    }),\n    <span class=\"hljs-string\">'bar'<\/span>\n  ]\n)\n<\/code><\/pre>\n<h3 id=\"\u5b8c\u6574\u6570\u636e\u5bf9\u8c61\">\u5b8c\u6574\u6570\u636e\u5bf9\u8c61<\/h3>\n<p>\u6709\u4e00\u4ef6\u4e8b\u8981\u6ce8\u610f\uff1a\u5728 templates \u4e2d\uff0c<code>v-bind:class<\/code>\u00a0\u548c\u00a0<code>v-bind:style<\/code>\u00a0\uff0c\u4f1a\u6709\u7279\u522b\u7684\u5904\u7406\uff0c\u4ed6\u4eec\u5728 VNode \u6570\u636e\u5bf9\u8c61\u4e2d\uff0c\u4e3a\u6700\u9ad8\u7ea7\u914d\u7f6e\u3002<\/p>\n<pre><code class=\"lang-js\">{\n  <span class=\"hljs-comment\">\/\/ \u548c`v-bind:class`\u4e00\u6837\u7684 API<\/span>\n  <span class=\"hljs-string\">'class'<\/span>: {\n    foo: <span class=\"hljs-literal\">true<\/span>,\n    bar: <span class=\"hljs-literal\">false<\/span>\n  },\n  <span class=\"hljs-comment\">\/\/ \u548c`v-bind:style`\u4e00\u6837\u7684 API<\/span>\n  style: {\n    color: <span class=\"hljs-string\">'red'<\/span>,\n    fontSize: <span class=\"hljs-string\">'14px'<\/span>\n  },\n  <span class=\"hljs-comment\">\/\/ \u6b63\u5e38\u7684 HTML \u7279\u6027<\/span>\n  attrs: {\n    id: <span class=\"hljs-string\">'foo'<\/span>\n  },\n  <span class=\"hljs-comment\">\/\/ \u7ec4\u4ef6 props<\/span>\n  props: {\n    myProp: <span class=\"hljs-string\">'bar'<\/span>\n  },\n  <span class=\"hljs-comment\">\/\/ DOM \u5c5e\u6027<\/span>\n  domProps: {\n    innerHTML: <span class=\"hljs-string\">'baz'<\/span>\n  },\n  <span class=\"hljs-comment\">\/\/ \u4e8b\u4ef6\u76d1\u542c\u5668\u57fa\u4e8e \"on\"<\/span>\n  <span class=\"hljs-comment\">\/\/ \u6240\u4ee5\u4e0d\u518d\u652f\u6301\u5982 v-on:keyup.enter \u4fee\u9970\u5668<\/span>\n  <span class=\"hljs-comment\">\/\/ \u9700\u8981\u624b\u52a8\u5339\u914d keyCode\u3002<\/span>\n  on: {\n    click: <span class=\"hljs-keyword\">this<\/span>.clickHandler\n  },\n  <span class=\"hljs-comment\">\/\/ \u4ec5\u5bf9\u4e8e\u7ec4\u4ef6\uff0c\u7528\u4e8e\u76d1\u542c\u539f\u751f\u4e8b\u4ef6\uff0c\u800c\u4e0d\u662f\u7ec4\u4ef6\u4f7f\u7528 vm.$emit \u89e6\u53d1\u7684\u4e8b\u4ef6\u3002<\/span>\n  nativeOn: {\n    click: <span class=\"hljs-keyword\">this<\/span>.nativeClickHandler\n  },\n  <span class=\"hljs-comment\">\/\/ \u81ea\u5b9a\u4e49\u6307\u4ee4. \u6ce8\u610f\u4e8b\u9879\uff1a\u4e0d\u80fd\u5bf9\u7ed1\u5b9a\u7684\u65e7\u503c\u8bbe\u503c<\/span>\n  <span class=\"hljs-comment\">\/\/ Vue \u4f1a\u4e3a\u60a8\u6301\u7eed\u8ffd\u8e28<\/span>\n  directives: [\n    {\n      name: <span class=\"hljs-string\">'my-custom-directive'<\/span>,\n      value: <span class=\"hljs-string\">'2'<\/span>\n      expression: <span class=\"hljs-string\">'1 + 1'<\/span>,\n      arg: <span class=\"hljs-string\">'foo'<\/span>,\n      modifiers: {\n        bar: <span class=\"hljs-literal\">true<\/span>\n      }\n    }\n  ],\n  <span class=\"hljs-comment\">\/\/ Scoped slots in the form of<\/span>\n  <span class=\"hljs-comment\">\/\/ { name: props =&gt; VNode | Array&lt;VNode&gt; }<\/span>\n  scopedSlots: {\n    <span class=\"hljs-keyword\">default<\/span>: props =&gt; h(<span class=\"hljs-string\">'span'<\/span>, props.text)\n  },\n  <span class=\"hljs-comment\">\/\/ \u5982\u679c\u5b50\u7ec4\u4ef6\u6709\u5b9a\u4e49 slot \u7684\u540d\u79f0<\/span>\n  slot: <span class=\"hljs-string\">'name-of-slot'<\/span>\n  <span class=\"hljs-comment\">\/\/ \u5176\u4ed6\u7279\u6b8a\u9876\u5c42\u5c5e\u6027<\/span>\n  key: <span class=\"hljs-string\">'myKey'<\/span>,\n  ref: <span class=\"hljs-string\">'myRef'<\/span>\n}\n<\/code><\/pre>\n<h3 id=\"\u5b8c\u6574\u793a\u4f8b\">\u5b8c\u6574\u793a\u4f8b<\/h3>\n<p>\u6709\u4e86\u8fd9\u65b9\u9762\u7684\u77e5\u8bc6\uff0c\u6211\u4eec\u73b0\u5728\u53ef\u4ee5\u5b8c\u6210\u6211\u4eec\u6700\u5f00\u59cb\u60f3\u5b9e\u73b0\u7684\u7ec4\u4ef6\uff1a<\/p>\n<pre><code class=\"lang-js\"><span class=\"hljs-keyword\">var<\/span> getChildrenTextContent = <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">children<\/span>) <\/span>{\n  <span class=\"hljs-keyword\">return<\/span> children.map(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">node<\/span>) <\/span>{\n    <span class=\"hljs-keyword\">return<\/span> node.children\n      ? getChildrenTextContent(node.children)\n      : node.text\n  }).join(<span class=\"hljs-string\">''<\/span>)\n}\n\nVue.component(<span class=\"hljs-string\">'anchored-heading'<\/span>, {\n  render: <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">createElement<\/span>) <\/span>{\n    <span class=\"hljs-comment\">\/\/ create kebabCase id<\/span>\n    <span class=\"hljs-keyword\">var<\/span> headingId = getChildrenTextContent(<span class=\"hljs-keyword\">this<\/span>.$slots.default)\n      .toLowerCase()\n      .replace(<span class=\"hljs-regexp\">\/\\W+\/g<\/span>, <span class=\"hljs-string\">'-'<\/span>)\n      .replace(<span class=\"hljs-regexp\">\/(^\\-|\\-$)\/g<\/span>, <span class=\"hljs-string\">''<\/span>)\n\n    <span class=\"hljs-keyword\">return<\/span> createElement(\n      <span class=\"hljs-string\">'h'<\/span> + <span class=\"hljs-keyword\">this<\/span>.level,\n      [\n        createElement(<span class=\"hljs-string\">'a'<\/span>, {\n          attrs: {\n            name: headingId,\n            href: <span class=\"hljs-string\">'#'<\/span> + headingId\n          }\n        }, <span class=\"hljs-keyword\">this<\/span>.$slots.default)\n      ]\n    )\n  },\n  props: {\n    level: {\n      type: <span class=\"hljs-built_in\">Number<\/span>,\n      required: <span class=\"hljs-literal\">true<\/span>\n    }\n  }\n})\n<\/code><\/pre>\n<h3 id=\"\u7ea6\u675f\">\u7ea6\u675f<\/h3>\n<h4 id=\"vnodes-\u5fc5\u987b\u552f\u4e00\">VNodes \u5fc5\u987b\u552f\u4e00<\/h4>\n<p>\u6240\u6709\u7ec4\u4ef6\u6811\u4e2d\u7684 VNodes \u5fc5\u987b\u552f\u4e00\u3002\u8fd9\u610f\u5473\u7740\uff0c\u4e0b\u9762\u7684 render function \u662f\u65e0\u6548\u7684\uff1a<\/p>\n<pre><code class=\"lang-js\">render: <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">createElement<\/span>) <\/span>{\n  <span class=\"hljs-keyword\">var<\/span> myParagraphVNode = createElement(<span class=\"hljs-string\">'p'<\/span>, <span class=\"hljs-string\">'hi'<\/span>)\n  <span class=\"hljs-keyword\">return<\/span> createElement(<span class=\"hljs-string\">'div'<\/span>, [\n    <span class=\"hljs-comment\">\/\/ Yikes - duplicate VNodes!<\/span>\n    myParagraphVNode, myParagraphVNode\n  ])\n}\n<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u771f\u7684\u9700\u8981\u91cd\u590d\u5f88\u591a\u6b21\u7684\u5143\u7d20\/\u7ec4\u4ef6\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5de5\u5382\u51fd\u6570\u6765\u5b9e\u73b0\u3002\u4f8b\u5982\uff0c\u4e0b\u9762\u8fd9\u4e2a\u4f8b\u5b50 render \u51fd\u6570\u5b8c\u7f8e\u6709\u6548\u5730\u6e32\u67d3\u4e86 20 \u4e2a\u91cd\u590d\u7684\u6bb5\u843d\uff1a<\/p>\n<pre><code class=\"lang-js\">render: <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">createElement<\/span>) <\/span>{\n  <span class=\"hljs-keyword\">return<\/span> createElement(<span class=\"hljs-string\">'div'<\/span>,\n    <span class=\"hljs-built_in\">Array<\/span>.apply(<span class=\"hljs-literal\">null<\/span>, { length: <span class=\"hljs-number\">20<\/span> }).map(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> () <\/span>{\n      <span class=\"hljs-keyword\">return<\/span> createElement(<span class=\"hljs-string\">'p'<\/span>, <span class=\"hljs-string\">'hi'<\/span>)\n    })\n  )\n}\n<\/code><\/pre>\n<h2 id=\"\u4f7f\u7528-javascript-\u4ee3\u66ff\u6a21\u677f\u529f\u80fd\">\u4f7f\u7528 JavaScript \u4ee3\u66ff\u6a21\u677f\u529f\u80fd<\/h2>\n<h3 id=\"v-if-and-v-for\"><code>v-if<\/code>\u00a0and\u00a0<code>v-for<\/code><\/h3>\n<p>\u65e0\u8bba\u4ec0\u4e48\u90fd\u53ef\u4ee5\u4f7f\u7528\u539f\u751f\u7684 JavaScript \u6765\u5b9e\u73b0\uff0cVue \u7684 render \u51fd\u6570\u4e0d\u4f1a\u63d0\u4f9b\u4e13\u7528\u7684 API\u3002\u6bd4\u5982\uff0c template \u4e2d\u7684\u00a0<code>v-if<\/code>\u00a0\u548c\u00a0<code>v-for<\/code>:<\/p>\n<pre><code class=\"lang-html\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">ul<\/span> <span class=\"hljs-attr\">v-if<\/span>=<span class=\"hljs-string\">\"items.length\"<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">li<\/span> <span class=\"hljs-attr\">v-for<\/span>=<span class=\"hljs-string\">\"item in items\"<\/span>&gt;<\/span>{{ item.name }}<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">li<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">ul<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span> <span class=\"hljs-attr\">v-else<\/span>&gt;<\/span>No items found.<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n<\/code><\/pre>\n<p>\u8fd9\u4e9b\u90fd\u4f1a\u5728 render \u51fd\u6570\u4e2d\u88ab JavaScript \u7684\u00a0<code>if<\/code>\/<code>else<\/code>\u00a0\u548c\u00a0<code>map<\/code>\u00a0\u91cd\u5199\uff1a<\/p>\n<pre><code class=\"lang-js\">render: <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">createElement<\/span>) <\/span>{\n  <span class=\"hljs-keyword\">if<\/span> (<span class=\"hljs-keyword\">this<\/span>.items.length) {\n    <span class=\"hljs-keyword\">return<\/span> createElement(<span class=\"hljs-string\">'ul'<\/span>, <span class=\"hljs-keyword\">this<\/span>.items.map(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">item<\/span>) <\/span>{\n      <span class=\"hljs-keyword\">return<\/span> createElement(<span class=\"hljs-string\">'li'<\/span>, item.name)\n    }))\n  } <span class=\"hljs-keyword\">else<\/span> {\n    <span class=\"hljs-keyword\">return<\/span> createElement(<span class=\"hljs-string\">'p'<\/span>, <span class=\"hljs-string\">'No items found.'<\/span>)\n  }\n}\n<\/code><\/pre>\n<h3 id=\"v-model\"><code>v-model<\/code><\/h3>\n<p>There is no direct\u00a0<code>v-model<\/code>\u00a0counterpart in render functions &#8211; you will have to implement the logic yourself:<\/p>\n<pre><code class=\"lang-js\">render: <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">createElement<\/span>) <\/span>{\n  <span class=\"hljs-keyword\">var<\/span> self = <span class=\"hljs-keyword\">this<\/span>\n  <span class=\"hljs-keyword\">return<\/span> createElement(<span class=\"hljs-string\">'input'<\/span>, {\n    domProps: {\n      value: self.value\n    },\n    on: {\n      input: <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">e<\/span>) <\/span>{\n        self.value = e.target.value\n      }\n    }\n  })\n}\n<\/code><\/pre>\n<p>This is the cost of going lower-level, but it also gives you much more control over the interaction details compared to\u00a0<code>v-model<\/code>.<\/p>\n<h3 id=\"slots\">Slots<\/h3>\n<p>You can access static slot contents as Arrays of VNodes from\u00a0<a href=\"http:\/\/vuejs.org\/v2\/api\/#vm-slots\" target=\"_blank\" rel=\"noopener\"><code>this.$slots<\/code><\/a>:<\/p>\n<pre><code class=\"lang-js\">render: <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">createElement<\/span>) <\/span>{\n  <span class=\"hljs-comment\">\/\/ &lt;div&gt;&lt;slot&gt;&lt;\/slot&gt;&lt;\/div&gt;<\/span>\n  <span class=\"hljs-keyword\">return<\/span> createElement(<span class=\"hljs-string\">'div'<\/span>, <span class=\"hljs-keyword\">this<\/span>.$slots.default)\n}\n<\/code><\/pre>\n<p>And access scoped slots as functions that return VNodes from\u00a0<a href=\"http:\/\/vuejs.org\/v2\/api\/#vm-scopedSlots\" target=\"_blank\" rel=\"noopener\"><code>this.$scopedSlots<\/code><\/a>:<\/p>\n<pre><code class=\"lang-js\">render: <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">createElement<\/span>) <\/span>{\n  <span class=\"hljs-comment\">\/\/ &lt;div&gt;&lt;slot :text=\"msg\"&gt;&lt;\/slot&gt;&lt;\/div&gt;<\/span>\n  <span class=\"hljs-keyword\">return<\/span> createElement(<span class=\"hljs-string\">'div'<\/span>, [\n    <span class=\"hljs-keyword\">this<\/span>.$scopedSlots.default({\n      text: <span class=\"hljs-keyword\">this<\/span>.msg\n    })\n  ])\n}\n<\/code><\/pre>\n<p>To pass scoped slots to a child component using render functions, use the\u00a0<code>scopedSlots<\/code>\u00a0field in VNode data:<\/p>\n<pre><code class=\"lang-js\">render (createElement) {\n  <span class=\"hljs-keyword\">return<\/span> createElement(<span class=\"hljs-string\">'div'<\/span>, [\n    createElement(<span class=\"hljs-string\">'child'<\/span>, {\n      <span class=\"hljs-comment\">\/\/ pass scopedSlots in the data object<\/span>\n      <span class=\"hljs-comment\">\/\/ in the form of { name: props =&gt; VNode | Array&lt;VNode&gt; }<\/span>\n      scopedSlots: {\n        <span class=\"hljs-keyword\">default<\/span>: <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">props<\/span>) <\/span>{\n          <span class=\"hljs-keyword\">return<\/span> h(<span class=\"hljs-string\">'span'<\/span>, props.text)\n        }\n      }\n    })\n  ])\n}\n<\/code><\/pre>\n<h2 id=\"jsx\">JSX<\/h2>\n<p>\u5982\u679c\u4f60\u5199\u4e86\u5f88\u591a\u00a0<code>render<\/code>\u00a0\u51fd\u6570\uff0c\u53ef\u80fd\u4f1a\u89c9\u5f97\u75db\u82e6\uff1a<\/p>\n<pre><code class=\"lang-js\">createElement(\n  <span class=\"hljs-string\">'anchored-heading'<\/span>, {\n    props: {\n      level: <span class=\"hljs-number\">1<\/span>\n    }\n  }, [\n    createElement(<span class=\"hljs-string\">'span'<\/span>, <span class=\"hljs-string\">'Hello'<\/span>),\n    <span class=\"hljs-string\">' world!'<\/span>\n  ]\n)\n<\/code><\/pre>\n<p>\u7279\u522b\u662f\u6a21\u677f\u5982\u6b64\u7b80\u5355\u7684\u60c5\u51b5\u4e0b\uff1a<\/p>\n<pre><code class=\"lang-html\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">anchored-heading<\/span> <span class=\"hljs-attr\">:level<\/span>=<span class=\"hljs-string\">\"1\"<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">span<\/span>&gt;<\/span>Hello<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">span<\/span>&gt;<\/span> world!\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">anchored-heading<\/span>&gt;<\/span>\n<\/code><\/pre>\n<p>\u8fd9\u5c31\u662f\u4f1a\u6709\u4e00\u4e2a\u00a0<a href=\"https:\/\/github.com\/vuejs\/babel-plugin-transform-vue-jsx\" target=\"_blank\" rel=\"noopener\">Babel plugin<\/a>\u00a0\u63d2\u4ef6\uff0c\u7528\u4e8e\u5728 Vue \u4e2d\u4f7f\u7528 JSX \u8bed\u6cd5\u7684\u539f\u56e0\uff0c\u5b83\u53ef\u4ee5\u8ba9\u6211\u4eec\u56de\u5230\u4e8e\u66f4\u63a5\u8fd1\u6a21\u677f\u7684\u8bed\u6cd5\u4e0a\u3002<\/p>\n<pre><code class=\"lang-js\"><span class=\"hljs-keyword\">import<\/span> AnchoredHeading <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/AnchoredHeading.vue'<\/span>\n\n<span class=\"hljs-keyword\">new<\/span> Vue({\n  el: <span class=\"hljs-string\">'#demo'<\/span>,\n  render (h) {\n    <span class=\"hljs-keyword\">return<\/span> (\n      <span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">AnchoredHeading<\/span> <span class=\"hljs-attr\">level<\/span>=<span class=\"hljs-string\">{1}<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">span<\/span>&gt;<\/span>Hello<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">span<\/span>&gt;<\/span> world!\n      <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">AnchoredHeading<\/span>&gt;<\/span><\/span>\n    )\n  }\n})\n<\/code><\/pre>\n<p class=\"tip\">\u5c06 `h` \u4f5c\u4e3a `createElement` \u7684\u522b\u540d\u662f\u4e00\u4e2a\u901a\u7528\u60ef\u4f8b\uff0c\u4f60\u4f1a\u53d1\u73b0\u5728 Vue \u751f\u6001\u7cfb\u7edf\u4e2d\uff0c\u5b9e\u9645\u4e0a\u5fc5\u987b\u7528\u5230 JSX\uff0c\u5982\u679c\u5728\u4f5c\u7528\u57df\u4e2d `h` \u5931\u53bb\u4f5c\u7528\uff0c \u5728\u5e94\u7528\u4e2d\u4f1a\u89e6\u53d1\u62a5\u9519\u3002<\/p>\n<p>\u66f4\u591a\u5173\u4e8e JSX \u6620\u5c04\u5230 JavaScript\uff0c\u9605\u8bfb\u00a0<a href=\"https:\/\/github.com\/vuejs\/babel-plugin-transform-vue-jsx#usage\" target=\"_blank\" rel=\"noopener\">\u4f7f\u7528\u6587\u6863<\/a>\u3002<\/p>\n<h2 id=\"\u51fd\u6570\u5316\u7ec4\u4ef6\">\u51fd\u6570\u5316\u7ec4\u4ef6<\/h2>\n<p>\u4e4b\u524d\u521b\u5efa\u7684\u951a\u70b9\u6807\u9898\u7ec4\u4ef6\u662f\u6bd4\u8f83\u7b80\u5355\uff0c\u6ca1\u6709\u7ba1\u7406\u6216\u8005\u76d1\u542c\u4efb\u4f55\u4f20\u9012\u7ed9\u4ed6\u7684\u72b6\u6001\uff0c\u4e5f\u6ca1\u6709\u751f\u547d\u5468\u671f\u65b9\u6cd5\u3002\u5b83\u53ea\u662f\u4e00\u4e2a\u63a5\u6536\u53c2\u6570\u7684\u51fd\u6570\u3002 \u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u6807\u8bb0\u7ec4\u4ef6\u4e3a\u00a0<code>functional<\/code>\uff0c \u8fd9\u610f\u5473\u5b83\u662f\u65e0\u72b6\u6001\uff08\u6ca1\u6709\u00a0<code>data<\/code>\uff09\uff0c\u65e0\u5b9e\u4f8b\uff08\u6ca1\u6709\u00a0<code>this<\/code>\u00a0\u4e0a\u4e0b\u6587\uff09\u3002 \u4e00\u4e2a\u00a0<strong>\u51fd\u6570\u5316\u7ec4\u4ef6<\/strong>\u00a0\u5c31\u50cf\u8fd9\u6837\uff1a<\/p>\n<pre><code class=\"lang-js\">Vue.component(<span class=\"hljs-string\">'my-component'<\/span>, {\n  functional: <span class=\"hljs-literal\">true<\/span>,\n  <span class=\"hljs-comment\">\/\/ \u4e3a\u4e86\u5f25\u8865\u7f3a\u5c11\u7684\u5b9e\u4f8b<\/span>\n  <span class=\"hljs-comment\">\/\/ \u63d0\u4f9b\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4f5c\u4e3a\u4e0a\u4e0b\u6587<\/span>\n  render: <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">createElement, context<\/span>) <\/span>{\n    <span class=\"hljs-comment\">\/\/ ...<\/span>\n  },\n  <span class=\"hljs-comment\">\/\/ Props \u53ef\u9009<\/span>\n  props: {\n    <span class=\"hljs-comment\">\/\/ ...<\/span>\n  }\n})\n<\/code><\/pre>\n<p>\u7ec4\u4ef6\u9700\u8981\u7684\u4e00\u5207\u90fd\u662f\u901a\u8fc7\u4e0a\u4e0b\u6587\u4f20\u9012\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><code>props<\/code>: \u63d0\u4f9bprops \u7684\u5bf9\u8c61<\/li>\n<li><code>children<\/code>: VNode \u5b50\u8282\u70b9\u7684\u6570\u7ec4<\/li>\n<li><code>slots<\/code>: slots \u5bf9\u8c61<\/li>\n<li><code>data<\/code>: \u4f20\u9012\u7ed9\u7ec4\u4ef6\u7684 data \u5bf9\u8c61<\/li>\n<li><code>parent<\/code>: \u5bf9\u7236\u7ec4\u4ef6\u7684\u5f15\u7528<\/li>\n<\/ul>\n<p>\u5728\u6dfb\u52a0\u00a0<code>functional: true<\/code>\u00a0\u4e4b\u540e\uff0c\u951a\u70b9\u6807\u9898\u7ec4\u4ef6\u7684 render \u51fd\u6570\u4e4b\u95f4\u7b80\u5355\u66f4\u65b0\u589e\u52a0\u00a0<code>context<\/code>\u00a0\u53c2\u6570\uff0c<code>this.$slots.default<\/code>\u00a0\u66f4\u65b0\u4e3a\u00a0<code>context.children<\/code>\uff0c\u4e4b\u540e<code>this.level<\/code>\u00a0\u66f4\u65b0\u4e3a\u00a0<code>context.props.level<\/code>\u3002<\/p>\n<p>\u51fd\u6570\u5316\u7ec4\u4ef6\u53ea\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u6240\u4ee5\u6e32\u67d3\u5f00\u9500\u4e5f\u4f4e\u5f88\u591a\u3002\u4f46\u540c\u6837\u5b83\u4e5f\u6709\u5b8c\u6574\u7684\u7ec4\u4ef6\u5c01\u88c5\uff0c\u4f60\u9700\u8981\u77e5\u9053\u8fd9\u4e9b\uff0c \u6bd4\u5982\uff1a<\/p>\n<ul>\n<li>\u7a0b\u5e8f\u5316\u5730\u5728\u591a\u4e2a\u7ec4\u4ef6\u4e2d\u9009\u62e9\u4e00\u4e2a<\/li>\n<li>\u5728\u5c06 children, props, data \u4f20\u9012\u7ed9\u5b50\u7ec4\u4ef6\u4e4b\u524d\u64cd\u4f5c\u5b83\u4eec\u3002<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f9d\u8d56\u4f20\u5165 props \u7684\u503c\u7684\u00a0<code>smart-list<\/code>\u00a0\u7ec4\u4ef6\u4f8b\u5b50\uff0c\u5b83\u80fd\u4ee3\u8868\u66f4\u591a\u5177\u4f53\u7684\u7ec4\u4ef6\uff1a<\/p>\n<pre><code class=\"lang-js\"><span class=\"hljs-keyword\">var<\/span> EmptyList = { <span class=\"hljs-comment\">\/* ... *\/<\/span> }\n<span class=\"hljs-keyword\">var<\/span> TableList = { <span class=\"hljs-comment\">\/* ... *\/<\/span> }\n<span class=\"hljs-keyword\">var<\/span> OrderedList = { <span class=\"hljs-comment\">\/* ... *\/<\/span> }\n<span class=\"hljs-keyword\">var<\/span> UnorderedList = { <span class=\"hljs-comment\">\/* ... *\/<\/span> }\n\nVue.component(<span class=\"hljs-string\">'smart-list'<\/span>, {\n  functional: <span class=\"hljs-literal\">true<\/span>,\n  render: <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> (<span class=\"hljs-params\">createElement, context<\/span>) <\/span>{\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">appropriateListComponent<\/span> () <\/span>{\n      <span class=\"hljs-keyword\">var<\/span> items = context.props.items\n\n      <span class=\"hljs-keyword\">if<\/span> (items.length === <span class=\"hljs-number\">0<\/span>)           <span class=\"hljs-keyword\">return<\/span> EmptyList\n      <span class=\"hljs-keyword\">if<\/span> (<span class=\"hljs-keyword\">typeof<\/span> items[<span class=\"hljs-number\">0<\/span>] === <span class=\"hljs-string\">'object'<\/span>) <span class=\"hljs-keyword\">return<\/span> TableList\n      <span class=\"hljs-keyword\">if<\/span> (context.props.isOrdered)      <span class=\"hljs-keyword\">return<\/span> OrderedList\n\n      <span class=\"hljs-keyword\">return<\/span> UnorderedList\n    }\n\n    <span class=\"hljs-keyword\">return<\/span> createElement(\n      appropriateListComponent(),\n      context.data,\n      context.children\n    )\n  },\n  props: {\n    items: {\n      type: <span class=\"hljs-built_in\">Array<\/span>,\n      required: <span class=\"hljs-literal\">true<\/span>\n    },\n    isOrdered: <span class=\"hljs-built_in\">Boolean<\/span>\n  }\n})\n<\/code><\/pre>\n<h3 id=\"slots-\u548c-children-\u5bf9\u6bd4\"><code>slots()<\/code>\u00a0\u548c\u00a0<code>children<\/code>\u00a0\u5bf9\u6bd4<\/h3>\n<p>\u4f60\u53ef\u80fd\u60f3\u77e5\u9053\u4e3a\u4ec0\u4e48\u540c\u65f6\u9700\u8981\u00a0<code>slots()<\/code>\u00a0\u548c\u00a0<code>children<\/code>\u3002<code>slots().default<\/code>\u00a0\u4e0d\u662f\u548c\u00a0<code>children<\/code>\u00a0\u7c7b\u4f3c\u7684\u5417\uff1f\u5728\u4e00\u4e9b\u573a\u666f\u4e2d\uff0c\u662f\u8fd9\u6837\uff0c\u4f46\u662f\u5982\u679c\u662f\u51fd\u6570\u5f0f\u7ec4\u4ef6\u548c\u4e0b\u9762\u8fd9\u6837\u7684 children \u5462\uff1f<\/p>\n<pre><code class=\"lang-html\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">my-functional-component<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span> <span class=\"hljs-attr\">slot<\/span>=<span class=\"hljs-string\">\"foo\"<\/span>&gt;<\/span>\n    first\n  <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>second<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">my-functional-component<\/span>&gt;<\/span>\n<\/code><\/pre>\n<p>\u5bf9\u4e8e\u8fd9\u4e2a\u7ec4\u4ef6\uff0c<code>children<\/code>\u00a0\u4f1a\u7ed9\u4f60\u4e24\u4e2a\u6bb5\u843d\u6807\u7b7e\uff0c\u800c\u00a0<code>slots().default<\/code>\u00a0\u53ea\u4f1a\u4f20\u9012\u7b2c\u4e8c\u4e2a\u533f\u540d\u6bb5\u843d\u6807\u7b7e\uff0c<code>slots().foo<\/code>\u00a0\u4f1a\u4f20\u9012\u7b2c\u4e00\u4e2a\u5177\u540d\u6bb5\u843d\u6807\u7b7e\u3002\u540c\u65f6\u62e5\u6709\u00a0<code>children<\/code>\u00a0\u548c\u00a0<code>slots()<\/code>\u00a0\uff0c\u56e0\u6b64\u4f60\u53ef\u4ee5\u9009\u62e9\u8ba9\u7ec4\u4ef6\u901a\u8fc7\u00a0<code>slot()<\/code>\u00a0\u7cfb\u7edf\u5206\u53d1\u6216\u8005\u7b80\u5355\u7684\u901a\u8fc7\u00a0<code>children<\/code>\u00a0\u63a5\u6536\uff0c\u8ba9\u5176\u4ed6\u7ec4\u4ef6\u53bb\u5904\u7406\u3002<\/p>\n<h2 id=\"\u6a21\u677f\u7f16\u8bd1\">\u6a21\u677f\u7f16\u8bd1<\/h2>\n<p>\u4f60\u53ef\u80fd\u6709\u5174\u8da3\u77e5\u9053\uff0cVue \u7684\u6a21\u677f\u5b9e\u9645\u662f\u7f16\u8bd1\u6210\u4e86 render \u51fd\u6570\u3002\u8fd9\u662f\u4e00\u4e2a\u5b9e\u73b0\u7ec6\u8282\uff0c\u901a\u5e38\u4e0d\u9700\u8981\u5173\u5fc3\uff0c\u4f46\u5982\u679c\u4f60\u60f3\u770b\u770b\u6a21\u677f\u7684\u529f\u80fd\u662f\u600e\u6837\u88ab\u7f16\u8bd1\u7684\uff0c\u4f60\u4f1a\u53d1\u73b0\u4f1a\u975e\u5e38\u6709\u8da3\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528\u00a0<code>Vue.compile<\/code>\u00a0\u6765\u5b9e\u65f6\u7f16\u8bd1\u6a21\u677f\u5b57\u7b26\u4e32\u7684\u7b80\u5355 demo\uff1a<\/p>\n<div id=\"vue-compile-demo\" class=\"demo\"><textarea rows=\"10\"><\/textarea><\/p>\n<div><label>render:<\/label><\/p>\n<pre><code>{{ result.render }}<\/code><\/pre>\n<p><label>staticRenderFns:<\/label><\/p>\n<pre><code>_m({{ index }}): {{ fn }}<\/code><\/pre>\n<\/div>\n<div><label>Compilation Error:<\/label><\/p>\n<pre><code>{{ result }}<\/code><\/pre>\n<\/div>\n<p>&lt;\/div&gt;<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u7840 Vue \u63a8\u8350\u4f7f\u7528\u5728\u7edd\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u4f7f\u7528 template \u6765\u521b\u5efa\u4f60\u7684 HTML\u3002\u7136\u800c\u5728\u4e00\u4e9b\u573a\u666f\u4e2d\uff0c\u4f60\u771f\u7684\u9700&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/posts\/65"}],"collection":[{"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":1,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":66,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/posts\/65\/revisions\/66"}],"wp:attachment":[{"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}