{"id":3826,"date":"2024-01-08T11:32:35","date_gmt":"2024-01-08T03:32:35","guid":{"rendered":"http:\/\/www.ponybai.com\/?p=3826"},"modified":"2023-12-02T11:33:00","modified_gmt":"2023-12-02T03:33:00","slug":"%e4%bd%bf%e7%94%a8dom","status":"publish","type":"post","link":"http:\/\/www.ponybai.com\/?p=3826","title":{"rendered":"\u4f7f\u7528 DOM"},"content":{"rendered":"\n<p>\u6587\u6863\u5bf9\u8c61\u6a21\u578b \uff08DOM\uff09 \u8868\u793a HTML \u9875\u9762\uff0c\u4ee5\u4fbf\u60a8\u53ef\u4ee5\u4f7f\u7528 JavaScript \u6216\u6807\u51c6 DOM API \u5904\u7406\u5176\u5185\u5bb9\u3001\u7ed3\u6784\u548c\u6837\u5f0f\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6 DOM API \u8bbf\u95ee\u7ec4\u4ef6\u4e2d\u7684\u5143\u7d20\uff0c\u65e0\u8bba\u662f\u5426\u4f7f\u7528\u6a21\u677f\u5f15\u7528\u9009\u62e9\u5668\u3002\u867d\u7136\u6211\u4eec\u4e0d\u5efa\u8bae\u64cd\u4f5c DOM\uff0c\u4f46\u67d0\u4e9b\u7b2c\u4e09\u65b9 JavaScript \u5e93\u9700\u8981\u63a5\u7ba1 DOM\u3002<code>querySelector()<\/code><\/p>\n\n\n\n<p>\u6709\u5173 DOM \u7684\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u00a0<em>MDN Web<\/em>\u00a0\u6587\u6863\uff1a\u6587\u6863\u5bf9\u8c61\u6a21\u578b \uff08DOM\uff09\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"access-elements-the-component-owns\">\u8bbf\u95ee\u7ec4\u4ef6\u62e5\u6709\u7684\u5143\u7d20<\/h2>\n\n\n\n<p>\u8981\u8bbf\u95ee\u4f7f\u7528\u6807\u51c6 DOM API \u7684\u7ec4\u4ef6\u5448\u73b0\u7684\u5143\u7d20\uff0c\u8bf7\u4f7f\u7528 \u6216 \u3002\u8981\u5728\u6ca1\u6709\u9009\u62e9\u5668\u7684\u60c5\u51b5\u4e0b\u67e5\u627e DOM \u4e2d\u7684\u5143\u7d20\uff0c\u8bf7\u4f7f\u7528 refs\u3002<code>querySelector()<\/code><code>this.template<\/code><code>this<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">querySelector\uff08\uff09<\/h2>\n\n\n\n<p>\u8bbf\u95ee DOM \u4e2d\u5143\u7d20\u7684\u6807\u51c6\u65b9\u6cd5\u662f\u4f7f\u7528 .\u8981\u67e5\u627e\u5f71\u5b50 DOM \u8282\u70b9\uff0c\u8bf7\u4f7f\u7528 \u6216 on \u3002\u5bf9\u4e8e\u8f7b\u91cf\u7ea7 DOM \u8282\u70b9\uff0c\u8bf7\u5728 \u4e0a\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u4e4b\u4e00\u3002<code>querySelector()<\/code><code>querySelector()<\/code><code>querySelectorAll()<\/code><code>this.template<\/code><code>this<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ shadow DOM\nthis.template.querySelector(\"div\");\n\n\/\/ light DOM\nthis.querySelector(\"div\");<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528 .<code>{element}.template.querySelector<\/code><\/p>\n\n\n\n<p>\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u67e5\u627e\u7ec4\u4ef6\u5448\u73b0\u7684\u5143\u7d20\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5143\u7d20\u7684\u987a\u5e8f\u4e0d\u4fdd\u8bc1\u3002<\/li>\n\n\n\n<li>\u672a\u5448\u73b0\u5230 DOM \u7684\u5143\u7d20\u4e0d\u4f1a\u5728\u7ed3\u679c\u4e2d\u8fd4\u56de\u3002<code>querySelector<\/code><\/li>\n\n\n\n<li>\u4e0d\u8981\u5c06 ID \u9009\u62e9\u5668\u4e0e \u4e00\u8d77\u4f7f\u7528\u3002\u5448\u73b0\u6a21\u677f\u65f6\uff0c\u5728 HTML \u6a21\u677f\u4e2d\u5b9a\u4e49\u7684 ID \u53ef\u80fd\u4f1a\u8f6c\u6362\u4e3a\u5168\u5c40\u552f\u4e00\u503c\u3002\u5982\u679c\u5728 JavaScript \u4e2d\u4f7f\u7528 ID \u9009\u62e9\u5668\uff0c\u5b83\u5c06\u4e0e\u8f6c\u6362\u540e\u7684 ID \u4e0d\u5339\u914d\u3002<code>querySelector<\/code><\/li>\n\n\n\n<li>\u5bf9\u4e8e\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\uff0c\u641c\u7d22\u76f4\u63a5\u6a21\u677f\u4e4b\u5916\u7684\u5143\u7d20\uff0c\u4f8b\u5982\u8f7b\u91cf\u7ea7 DOM \u5b50\u7ea7\u3002\u4f7f\u7528\u66f4\u5177\u4f53\u7684\u9009\u62e9\u5668\u6765\u7f29\u5c0f\u65b9\u6cd5\u7684\u8303\u56f4\u3002<code>this.querySelector()<\/code><\/li>\n\n\n\n<li>\u5982\u679c\u7ec4\u4ef6\u5728\u542f\u7528\u4e86 Lightning Locker \u7684\u7ec4\u7ec7\u4e2d\u8fd0\u884c\uff0c\u8bf7\u6ce8\u610f\u6f5c\u5728\u7684\u5185\u5b58\u6cc4\u6f0f\u3002\u5982\u679c\u53ef\u80fd\uff0c\u7ec4\u7ec7\u5e94\u542f\u7528 Lightning Web Security\u3002\u6216\u8005\uff0c\u8003\u8651\u4f7f\u7528 refs \u800c\u4e0d\u662f .<code>querySelector<\/code><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- example.html --&gt;\n&lt;template&gt;\n  &lt;div&gt;First &lt;slot name=\"task1\"&gt;Task 1&lt;\/slot&gt;&lt;\/div&gt;\n  &lt;div&gt;Second &lt;slot name=\"task2\"&gt;Task 2&lt;\/slot&gt;&lt;\/div&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ example.js\nimport { LightningElement } from \"lwc\";\n\nexport default class Example extends LightningElement {\n  renderedCallback() {\n    this.template.querySelector(\"div\"); \/\/ &lt;div&gt;First&lt;\/div&gt;\n    this.template.querySelector(\"span\"); \/\/ null\n    this.template.querySelectorAll(\"div\"); \/\/ &#91;&lt;div&gt;First&lt;\/div&gt;, &lt;div&gt;Second&lt;\/div&gt;]\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u91cd\u8981<\/p>\n\n\n\n<p>\u4e0d\u8981\u4f7f\u7528 \u6216 \u5168\u5c40\u5c5e\u6027\u6765\u67e5\u8be2 DOM \u5143\u7d20\u3002\u8bf7\u53c2\u9605\u00a0DOM \u8bbf\u95ee\u904f\u5236\u3002\u6b64\u5916\uff0c\u6211\u4eec\u4e0d\u5efa\u8bae\u4f7f\u7528 JavaScript \u6765\u64cd\u4f5c DOM\uff0c\u9664\u975e\u60a8\u901a\u8fc7\u00a0<code>lightning\/platformResourceLoader<\/code>\u00a0\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u3002\u6700\u597d\u4f7f\u7528 Lightning Web \u7ec4\u4ef6\u00a0HTML \u6307\u4ee4\u6765\u7f16\u5199\u58f0\u660e\u6027\u4ee3\u7801\u3002<code>windowdocument<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u88c1\u5224<\/h2>\n\n\n\n<p>Refs \u67e5\u627e\u6ca1\u6709\u9009\u62e9\u5668\u7684 DOM \u5143\u7d20\uff0c\u5e76\u4e14\u53ea\u67e5\u8be2\u5305\u542b\u5728\u6307\u5b9a\u6a21\u677f\u4e2d\u7684\u5143\u7d20\u3002\u9996\u5148\uff0c\u5c06\u6307\u4ee4\u6dfb\u52a0\u5230\u5143\u7d20\u4e2d\u5e76\u4e3a\u5176\u8d4b\u503c\u3002\u8981\u8c03\u7528\u8be5\u5f15\u7528\uff0c\u8bf7\u4f7f\u7528 .\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u8be5\u5143\u7d20\u5177\u6709\u6307\u4ee4 \uff0c\u8be5\u6307\u4ee4\u5f15\u7528\u4ee5\u8bbf\u95ee at \u8fd0\u884c\u65f6\u3002<code>lwc:ref<\/code><code>this.refs<\/code><code>&lt;div&gt;<\/code><code>lwc:ref=\"myDiv\"<\/code><code>this.refs<\/code><code>&lt;div&gt;<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n  &lt;div lwc:ref=\"myDiv\"&gt;&lt;\/div&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>export default class extends LightningElement {\n  renderedCallback() {\n    console.log(this.refs.myDiv);\n  }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u8003\u8651<\/h3>\n\n\n\n<p>\u5728\u8c03\u7528 \u4e4b\u524d\uff0c\u5fc5\u987b\u5b9a\u4e49\u8be5\u6307\u4ee4\u3002\u5982\u679c\u8c03\u7528\u4e0d\u5b58\u5728\u7684 ref\uff0c\u5219\u8fd4\u56de .\u5982\u679c\u6a21\u677f\u5305\u542b\u91cd\u590d\u7684\u6307\u4ee4\uff0c\u5219\u5f15\u7528\u6700\u540e\u4e00\u4e2a .<code>lwc:ref<\/code><code>this.refs<\/code><code>this.refs<\/code><code>undefined<\/code><code>lwc:ref<\/code><code>this.refs<\/code><code>&lt;div&gt;<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n  &lt;div lwc:ref=\"myDiv\"&gt;&lt;\/div&gt;\n  &lt;div lwc:ref=\"myDiv\"&gt;&lt;\/div&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p><code>this.refs<\/code>\u662f\u4e00\u4e2a\u666e\u901a\u7684\u53ea\u8bfb\u5bf9\u8c61\u3002\u5c1d\u8bd5\u5728\u5176\u7ec4\u4ef6\u4e2d\u6dfb\u52a0\u3001\u4fee\u6539\u6216\u5220\u9664\u5c5e\u6027\u4f1a\u5bfc\u81f4\u8fd0\u884c\u65f6\u9519\u8bef\u3002\u5b83\u7684\u952e\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5b83\u7684\u503c\u662f\u4e00\u4e2a DOM \u5143\u7d20\u3002\u5728 light DOM \u548c shadow DOM \u4e2d\u5f15\u7528\u5143\u7d20\u7684\u8bed\u6cd5\u662f\u76f8\u540c\u7684\u3002<code>this.refs<\/code><\/p>\n\n\n\n<p>Ref \u662f\u53ef\u914d\u7f6e\u548c\u53ef\u5199\u7684\uff0c\u56e0\u6b64\u5728\u7ec4\u4ef6\u4e2d\u5b9a\u4e49\u7684 ref \u4f1a\u8986\u76d6 \u4e2d\u7684 ref\u3002<code>LightningElement.prototype<\/code><\/p>\n\n\n\n<p>\u60a8\u4e0d\u80fd\u5e94\u7528\u4e8e\u5143\u7d20\uff0c\u4e5f\u4e0d\u80fd\u5e94\u7528\u4e8e\u8f7b\u91cf\u7ea7 DOM \u4e2d\u7684\u5143\u7d20\u3002<code>lwc:ref<\/code><code>&lt;template&gt;<\/code><code>&lt;slot&gt;<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template lwc:render-mode=\"light\"&gt;\n  &lt;template lwc:if={myTemplate} lwc:ref=\"myTemplate\"&gt;&lt;\/template&gt;\n  &lt;!-- Not allowed --&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template lwc:render-mode=\"light\"&gt;\n  &lt;slot lwc:ref=\"mySlot\"&gt;&lt;\/slot&gt;\n  &lt;!-- Not allowed --&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u5c06 or \u5faa\u73af\u7f6e\u4e8e or \u5faa\u73af\u4e2d\uff0c\u6a21\u677f\u7f16\u8bd1\u5668\u5c06\u5f15\u53d1\u9519\u8bef\u3002<code>lwc:ref<\/code><code>for:each<\/code><code>iterator:*<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template for:each={items} for:item=\"item\"&gt;\n  &lt;div key={item} lwc:ref=\"foo\"&gt;&lt;\/div&gt;\n  &lt;!-- Not allowed --&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u591a\u4e2a\u6a21\u677f<\/h3>\n\n\n\n<p><code>this.refs<\/code>\u6307\u591a\u6a21\u677f\u7ec4\u4ef6\u4e2d\u6700\u8fd1\u5448\u73b0\u7684\u6a21\u677f\u3002\u5f53\u6a21\u677f\u66f4\u6539\u65f6\uff0c\u5bf9\u8c61\u4e5f\u4f1a\u66f4\u6539\u3002<code>this.refs<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import a from \".\/a.html\";\nimport b from \".\/b.html\";\n\nexport default class extends LightningElement {\n  count = 0;\n\n  render() {\n    return this.count % 2 === 0 ? a : b;\n  }\n\n  renderedCallback() {\n    console.log(this.refs);\n  }\n\n  increment() {\n    this.count++;\n  }\n}\n\nconst cmp = createElement(\"c-component\", { is: Component });\n\/\/ Logs `this.refs` for a.html\n\ncmp.increment();\n\/\/ Logs `this.refs` for b.html\n\ncmp.increment();\n\/\/ Logs `this.refs` for a.html<\/code><\/pre>\n\n\n\n<p>\u8981\u6709\u6761\u4ef6\u5730\u5b9a\u4e49\u57fa\u4e8e \u7684\u5143\u7d20\uff0c\u8bf7\u5728\u4e00\u4e2a\u7236\u6a21\u677f\u4e0b\u521b\u5efa\u591a\u4e2a\u5b50\u6a21\u677f\u3002\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u6307\u5448\u73b0\u7684\u4efb\u4f55\u5b50\u6a21\u677f\u4e2d\u7684\u5143\u7d20\u3002<code>&lt;template lwc:if={boolean}&gt;<\/code><code>this.refs.toggleDarkMode<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template>\n  &lt;template lwc:if={darkMode}>\n    &lt;button lwc:ref=\"toggleDarkMode\">Enable Light Mode&lt;\/button>\n  &lt;\/template>\n  &lt;template lwc:else>\n    &lt;button lwc:ref=\"toggleDarkMode\">Enable Dark Mode&lt;\/button>\n  &lt;\/template>\n&lt;\/template>\n\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"shadow-dom\">\u5f71\u5b50 DOM<\/h2>\n\n\n\n<p>Shadow DOM \u662f\u4e00\u79cd\u5c01\u88c5 Web \u7ec4\u4ef6\u7684\u5185\u90e8\u6587\u6863\u5bf9\u8c61\u6a21\u578b \uff08DOM\uff09 \u7ed3\u6784\u7684\u6807\u51c6\u3002\u5c01\u88c5 DOM \u4f7f\u5f00\u53d1\u4eba\u5458\u80fd\u591f\u5171\u4eab\u7ec4\u4ef6\u5e76\u4fdd\u62a4\u7ec4\u4ef6\u4e0d\u88ab\u4efb\u610f HTML\u3001CSS \u548c JavaScript \u64cd\u7eb5\u3002\u5185\u90e8 DOM \u7ed3\u6784\u79f0\u4e3a\u5f71\u5b50\u6811\u3002\u5f71\u5b50\u6811\u4f1a\u5f71\u54cd\u60a8\u4f7f\u7528 CSS\u3001\u4e8b\u4ef6\u548c DOM \u7684\u65b9\u5f0f\u3002<\/p>\n\n\n\n<p>\u7531\u4e8e\u5e76\u975e\u6240\u6709\u6d4f\u89c8\u5668\u90fd\u5b9e\u73b0\u4e86\u5f71\u5b50 DOM\uff0c\u56e0\u6b64 LWC \u5bf9 Lightning Experience \u548c Experience Cloud \u4f7f\u7528\u5408\u6210\u5f71\u5b50 polyfill\u3002polyfill \u662f\u5141\u8bb8\u529f\u80fd\u5728 Web \u6d4f\u89c8\u5668\u4e2d\u5de5\u4f5c\u7684\u4ee3\u7801\u3002<\/p>\n\n\n\n<p>\u89e3\u91ca\u5f71\u5b50 DOM<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-rich\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/youtube.com\/watch?v=K5i9zMzVlzM\n<\/div><\/figure>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u5982\u679c\u60a8\u5728 Lightning Experience \u6216 Experience Cloud \u4e4b\u5916\u4f7f\u7528 LWC\uff0c\u4f8b\u5982\u5728 Lightning Out \u4e2d\uff0cLWC \u5c06\u5728\u539f\u751f\u9634\u5f71\u4e2d\u6e32\u67d3\u3002\u8bf7\u53c2\u9605\u00a0Salesforce Platform \u4e0a\u7684\u7f16\u8bd1\u65f6\u5dee\u5f02\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5f71\u5b50\u6811<\/h2>\n\n\n\n<p>\u4e3a\u4e86\u7406\u89e3\u5f71\u5b50\u6811\uff0c\u8ba9\u6211\u4eec\u770b\u4e00\u4e9b\u6807\u8bb0\u3002\u6b64\u6807\u8bb0\u5305\u542b\u4e24\u4e2a Lightning Web \u7ec4\u4ef6\uff1a\u548c .\u6587\u6863\u7247\u6bb5\u5b9a\u4e49\u4e86 DOM \u548c\u5f71\u5b50\u6811\u4e4b\u95f4\u7684\u8fb9\u754c\u3002\u9634\u5f71\u6839\u4e0b\u65b9\u7684\u5143\u7d20\u4f4d\u4e8e\u9634\u5f71\u6811\u4e2d\u3002<code>c-todo-appc-todo-item#shadow-root<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;c-todo-app&gt;\n  #shadow-root\n  &lt;div&gt;\n    &lt;p&gt;Your To Do List&lt;\/p&gt;\n  &lt;\/div&gt;\n  &lt;c-todo-item&gt;\n    #shadow-root\n    &lt;div&gt;\n      &lt;p&gt;Go to the store&lt;\/p&gt;\n    &lt;\/div&gt;\n  &lt;\/c-todo-item&gt;\n&lt;\/c-todo-app&gt;<\/code><\/pre>\n\n\n\n<p>\u8ba9\u6211\u4eec\u770b\u770b\u5982\u4f55\u5728\u8fd9\u4e9b\u533a\u57df\u4e2d\u4f7f\u7528\u9634\u5f71\u6811\u3002CSS\u7684<\/p>\n\n\n\n<p>\u5728\u7236\u7ec4\u4ef6\u4e2d\u5b9a\u4e49\u7684 CSS \u6837\u5f0f\u4e0d\u4f1a\u6cc4\u6f0f\u5230\u5b50\u7ec4\u4ef6\u4e2d\u3002\u5728\u6211\u4eec\u7684\u793a\u4f8b\u4e2d\uff0c\u6837\u5f0f\u8868\u4e2d\u5b9a\u4e49\u7684\u6837\u5f0f\u4e0d\u4f1a\u8bbe\u7f6e\u7ec4\u4ef6\u4e2d\u5143\u7d20\u7684\u6837\u5f0f\uff0c\u56e0\u4e3a\u6837\u5f0f\u4e0d\u4f1a\u8fdb\u5165\u9634\u5f71\u6811\u3002\u8bf7\u53c2\u9605\u00a0CSS\u3002<code>ptodoApp.csspc-todo-item<\/code>\u4e8b\u4ef6<\/p>\n\n\n\n<p>\u4e3a\u4e86\u9632\u6b62\u66b4\u9732\u7ec4\u4ef6\u7684\u5185\u90e8\u8be6\u7ec6\u4fe1\u606f\uff0c\u5982\u679c\u4e8b\u4ef6\u5192\u6ce1\u5e76\u8d8a\u8fc7\u9634\u5f71\u8fb9\u754c\uff0c\u5219\u67d0\u4e9b\u5c5e\u6027\u503c\u4f1a\u66f4\u6539\u4ee5\u5339\u914d\u4fa6\u542c\u5668\u7684\u8303\u56f4\u3002\u8bf7\u53c2\u9605\u4e8b\u4ef6\u91cd\u5b9a\u5411\u3002\u8bbf\u95ee\u5143\u7d20<\/p>\n\n\n\n<p>\u5f71\u5b50\u6811\u4e2d\u7684\u5143\u7d20\u65e0\u6cd5\u901a\u8fc7\u4f20\u7edf\u7684 DOM \u67e5\u8be2\u65b9\u6cd5\u8bbf\u95ee\u3002\u4ee3\u7801\u65e0\u6cd5\u4f7f\u7528\u6216\u8bbf\u95ee Lightning Web \u7ec4\u4ef6\u7684\u5f71\u5b50\u6811\u3002\u4f8b\u5982\uff0c\u4ee3\u7801\u65e0\u6cd5\u8c03\u7528\u4ee5\u9009\u62e9 Lightning Web \u7ec4\u4ef6\u7684\u5f71\u5b50\u6811\u4e2d\u7684\u8282\u70b9\u3002\u8981\u8bbf\u95ee\u81ea\u5df1\u7684\u5f71\u5b50\u6811\uff0cLightning Web \u7ec4\u4ef6\u4f1a\u8c03\u7528 .\u8bf7\u53c2\u9605\u7ec4\u4ef6\u62e5\u6709\u7684 Access \u5143\u7d20\u3002<code>documentdocument.bodydocument.querySelector()this.template.querySelector()<\/code>\u8bbf\u95ee\u63d2\u69fd<\/p>\n\n\n\n<p>\u63d2\u69fd\u662f\u7236\u7ec4\u4ef6\u4f20\u9012\u5230\u7ec4\u4ef6\u4e3b\u4f53\u4e2d\u7684\u6807\u8bb0\u7684\u5360\u4f4d\u7b26\u3002\u901a\u8fc7\u63d2\u69fd\u4f20\u9012\u7ed9\u7ec4\u4ef6\u7684 DOM \u5143\u7d20\u4e0d\u5f52\u8be5\u7ec4\u4ef6\u6240\u6709\uff0c\u4e5f\u4e0d\u5728\u7ec4\u4ef6\u7684\u5f71\u5b50\u6811\u4e2d\u3002\u8981\u8bbf\u95ee\u901a\u8fc7\u63d2\u69fd\u4f20\u9012\u7684 DOM \u5143\u7d20\uff0c\u8bf7\u8c03\u7528 \u3002\u8be5\u7ec4\u4ef6\u4e0d\u62e5\u6709\u8fd9\u4e9b\u5143\u7d20\uff0c\u56e0\u6b64\u60a8\u4e0d\u4f7f\u7528 .\u8bf7\u53c2\u9605\u5c06\u6807\u8bb0\u4f20\u9012\u5230\u69fd\u4e2d\u3002<code>this.querySelector()template<\/code>\u6d4b\u8bd5\u7ec4\u4ef6<\/p>\n\n\n\n<p>\u8bf7\u53c2\u9605\u00a0DOM \u68c0\u67e5\u6d4b\u8bd5\u53ef\u80fd\u4f1a\u53d1\u751f\u53d8\u5316\u3002<\/p>\n\n\n\n<p>\u63d0\u793a<\/p>\n\n\n\n<p>\u89c2\u770b Salesforce \u5f00\u53d1\u4eba\u5458\u5e03\u9053\u5e08 Alba Rivas\u00a0\u5bf9 Shadow DOM \u7684\u89e3\u91ca\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">DOM API \u63a5\u53e3<\/h2>\n\n\n\n<p>\u4e0d\u8981\u4f7f\u7528\u8fd9\u4e9b DOM API \u8bbf\u95ee\u4f7f\u7528 Lightning Locker \u7684\u7ec4\u7ec7\u4e2d\u7684\u7ec4\u4ef6\u5f71\u5b50\u6811\u3002\u5982\u679c\u60a8\u4f7f\u7528\u7684\u7b2c\u4e09\u65b9 JavaScript \u5e93\u4f7f\u7528\u8fd9\u4e9b DOM API \u8bbf\u95ee\u7ec4\u4ef6\u7684\u5f71\u5b50\u6811\uff0c\u8bf7\u4e0e\u5e93\u4f5c\u8005\u5408\u4f5c\u63d0\u4ea4\u5e76\u4fee\u590d\u95ee\u9898\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Document.prototype.getElementById<\/code><\/li>\n\n\n\n<li><code>Document.prototype.querySelector<\/code><\/li>\n\n\n\n<li><code>Document.prototype.querySelectorAll<\/code><\/li>\n\n\n\n<li><code>Document.prototype.getElementsByClassName<\/code><\/li>\n\n\n\n<li><code>Document.prototype.getElementsByTagName<\/code><\/li>\n\n\n\n<li><code>Document.prototype.getElementsByTagNameNS<\/code><\/li>\n\n\n\n<li><code>Document.prototype.getElementsByName<\/code><\/li>\n\n\n\n<li><code>document.body.querySelector<\/code><\/li>\n\n\n\n<li><code>document.body.querySelectorAll<\/code><\/li>\n\n\n\n<li><code>document.body.getElementsByClassName<\/code><\/li>\n\n\n\n<li><code>document.body.getElementsByTagName<\/code><\/li>\n\n\n\n<li><code>document.body.getElementsByTagNameNS<\/code><\/li>\n<\/ul>\n\n\n\n<p>Lightning Locker \u901a\u8fc7\u963b\u6b62\u8fd9\u4e9b API \u6765\u9632\u6b62\u60a8\u7834\u574f Lightning Web \u7ec4\u4ef6\u4e4b\u95f4\u7684\u5f71\u5b50 DOM \u5c01\u88c5\u3002\u4f46\u662f\uff0c\u5728 Aura \u7ec4\u4ef6\u7248\u672c 39.0 \u53ca\u66f4\u65e9\u7248\u672c\u4e2d\uff0cLightning Locker \u5728\u7ec4\u4ef6\u7ea7\u522b\u88ab\u7981\u7528\uff0c\u56e0\u6b64 Aura \u7ec4\u4ef6\u7684\u4ee3\u7801\u53ef\u80fd\u4f1a\u5931\u8d25\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e9b API \u4e0d\u53d7\u00a0Lightning Web Security\u00a0\uff08LWS\uff09 \u7684\u9650\u5236\u3002LWS \u901a\u8fc7\u5bf9\u6240\u6709\u7ec4\u4ef6\u7684 ShadowRoot \u5c5e\u6027\u5f3a\u5236\u6267\u884c\u503c\u6765\u9632\u6b62\u7834\u574f\u5f71\u5b50 DOM \u5c01\u88c5\u3002<code>closedmode<\/code><\/p>\n\n\n\n<p>\u91cd\u8981<\/p>\n\n\n\n<p>Shadow DOM polyfill \u5305\u542b\u63a5\u53e3\u7684\u8865\u4e01\u3002\u5982\u679c\u60a8\u4e60\u60ef\u4e8e\u76d1\u89c6 DOM \u6811\u4e2d\u7684\u66f4\u6539\uff0c\u8bf7\u65ad\u5f00\u5b83\uff0c\u5426\u5219\u5c06\u9020\u6210\u5185\u5b58\u6cc4\u6f0f\u3002\u8bf7\u6ce8\u610f\uff0c\u7ec4\u4ef6\u53ea\u80fd\u5728\u5176\u81ea\u5df1\u7684\u6a21\u677f\u4e2d\u89c2\u5bdf\u5230\u7a81\u53d8\u3002\u5b83\u65e0\u6cd5\u89c2\u5bdf\u5230\u5176\u4ed6\u81ea\u5b9a\u4e49\u5143\u7d20\u7684\u5f71\u5b50\u6811\u4e2d\u7684\u7a81\u53d8\u3002<code>MutationObserver<\/code><code>MutationObserver<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"light-dom\">\u8f7b\u91cf\u7ea7 DOM<\/h2>\n\n\n\n<p>Lightning Web \u7ec4\u4ef6\u76ee\u524d\u5728\u6bcf\u4e2a\u7ec4\u4ef6\u4e0a\u5f3a\u5236\u6267\u884c\u5f71\u5b50 DOM\uff0c\u5c01\u88c5\u7ec4\u4ef6\u7684\u5185\u90e8\u6807\u8bb0\uff0c\u5e76\u4f7f\u7f16\u7a0b\u4ee3\u7801\u65e0\u6cd5\u8bbf\u95ee\u5b83\u3002\u5f53\u60a8\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM \u65f6\uff0c\u60a8\u7684\u7ec4\u4ef6\u4f4d\u4e8e\u5f71\u5b50 DOM \u4e4b\u5916\uff0c\u5e76\u907f\u514d\u4e86\u5f71\u5b50 DOM \u9650\u5236\u3002\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5316\u4e86\u7b2c\u4e09\u65b9\u96c6\u6210\u548c\u5168\u5c40\u6837\u5f0f\u8bbe\u7f6e\u3002<\/p>\n\n\n\n<p>\u5728\u6df1\u5165\u63a2\u8ba8\u8f7b\u91cf\u7ea7 DOM \u7684\u7ec6\u8282\u4e4b\u524d\uff0c\u8ba9\u6211\u4eec\u5148\u770b\u770b\u4e0d\u540c\u7684 DOM \u7ed3\u6784\u662f\u5982\u4f55\u5728 DOM \u4e2d\u5448\u73b0\u7684\u3002\u9996\u5148\uff0c\u8003\u8651\u5f71\u5b50\u6811\u7684\u4e00\u4e9b\u6807\u8bb0\u3002\u539f\u751f\u5f71\u5b50 DOM\u00a0\u5728\u6807\u7b7e\u4e2d\u5448\u73b0\u7ec4\u4ef6\u3002\u4f46\u662f\uff0cLightning Experience \u548c Experience Cloud \u6539\u7528\u5408\u6210\u9634\u5f71\uff0c\u8fd9\u6a21\u4eff\u4e86\u672c\u673a\u9634\u5f71\u884c\u4e3a\u3002<code>#shadow-root<\/code><\/p>\n\n\n\n<p>\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM \u65f6\uff0c\u7ec4\u4ef6\u5185\u5bb9\u5c06\u9644\u52a0\u5230\u4e3b\u673a\u5143\u7d20\uff0c\u800c\u4e0d\u662f\u5176\u5f71\u5b50\u6811\u3002\u7136\u540e\uff0c\u53ef\u4ee5\u50cf\u6587\u6863\u5bbf\u4e3b\u4e2d\u7684\u4efb\u4f55\u5176\u4ed6\u5185\u5bb9\u4e00\u6837\u8bbf\u95ee\u5b83\uff0c\u4ece\u800c\u63d0\u4f9b\u4e0e\u4e0d\u53d7\u5f71\u5b50 DOM \u7ea6\u675f\u7684\u5185\u5bb9\u7c7b\u4f3c\u7684\u884c\u4e3a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;my-app&gt;\n  &lt;my-header&gt;\n    &lt;p&gt;Hello World&lt;\/p&gt;\n  &lt;\/my-header&gt;\n&lt;\/my-app&gt;<\/code><\/pre>\n\n\n\n<p>\u5982\u9700\u5168\u9762\u6982\u8ff0\uff0c\u8bf7\u53c2\u9605\u00a0Google Web Fundamentals\uff1a Shadow DOM v1\u3002<\/p>\n\n\n\n<p>\u4e0e\u5f71\u5b50 DOM \u76f8\u6bd4\uff0cLight DOM \u5177\u6709\u51e0\u4e2a\u4f18\u70b9\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>CSS \u4e3b\u9898<\/strong>\u548c\u54c1\u724c\uff1aLight DOM \u652f\u6301\u5168\u5c40\u6837\u5f0f\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u81ea\u5b9a\u4e49\u54c1\u724c\u5e94\u7528\u4e8e\u7ec4\u4ef6\u548c\u5b50\u7ec4\u4ef6\u3002<\/li>\n\n\n\n<li><strong>\u7b2c\u4e09\u65b9\u5de5\u5177\u548c\u6d4b\u8bd5<\/strong>\uff1a\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM\uff0c\u7b2c\u4e09\u65b9\u5de5\u5177\u53ef\u4ee5\u904d\u5386 DOM\uff0c\u4ece\u800c\u542f\u7528\u6807\u51c6\u7684\u6d4f\u89c8\u5668\u67e5\u8be2 API\uff08\u5982 \u548c\uff09\uff0c\u800c\u65e0\u9700\u904d\u5386\u5f71\u5b50\u6839\u3002\u4f8b\u5982\uff0c\u8f7b\u91cf\u7ea7 DOM \u4f7f\u00a0LWR \u7ad9\u70b9\u4e2d\u7684\u6807\u51c6\u7ec4\u4ef6\u80fd\u591f\u8ddf\u8e2a\u4e8b\u4ef6\u3002<code>querySelectorquerySelectorAll<\/code><\/li>\n\n\n\n<li><strong>\u53ef\u8bbf\u95ee\u6027<\/strong>\uff1aLight DOM \u4e0d\u9650\u5b9a ID \u7684\u8303\u56f4\uff0c\u5e76\u5141\u8bb8\u4e24\u4e2a\u5355\u72ec\u7684\u7ec4\u4ef6\u5f15\u7528\u53e6\u4e00\u4e2a ID\u3002\u4f8b\u5982\uff0c\u5373\u4f7f\u5143\u7d20\u4f4d\u4e8e\u5355\u72ec\u7684\u7ec4\u4ef6\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u5f15\u7528\u3002<code>&lt;label for=\"my-input\"&gt;<\/code><code>&lt;input type=\"text\" id=\"my-input\"&gt;<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u7528 Light DOM \u7684\u51c6\u5219<\/h2>\n\n\n\n<p>\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM \u4f1a\u4f7f\u60a8\u7684\u7ec4\u4ef6\u66b4\u9732\u7ed9 DOM \u6293\u53d6\uff0c\u56e0\u6b64\uff0c\u5982\u679c\u60a8\u6b63\u5728\u5904\u7406\u654f\u611f\u6570\u636e\uff0c\u6211\u4eec\u5efa\u8bae\u6539\u7528\u5f71\u5b50 DOM\u3002\u6362\u8a00\u4e4b\uff0c\u8f7b\u91cf\u7ea7 DOM \u4e0d\u63d0\u4f9b\u5f71\u5b50 DOM \u5c01\u88c5\u5e26\u6765\u7684\u597d\u5904\uff0c\u540e\u8005\u53ef\u4ee5\u9632\u6b62\u672a\u7ecf\u6388\u6743\u8bbf\u95ee\u5f71\u5b50\u6811\u3002\u7531\u4e8e DOM \u5bf9\u5176\u4ed6\u7ec4\u4ef6\u548c\u7b2c\u4e09\u65b9\u5de5\u5177\u7684\u904d\u5386\u662f\u5f00\u653e\u7684\uff0c\u56e0\u6b64\u60a8\u6709\u8d23\u4efb\u4fdd\u62a4\u60a8\u7684\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u3002<\/p>\n\n\n\n<p>\u5728\u5e94\u7528\u4e2d\u540c\u65f6\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM \u548c\u5f71\u5b50 DOM \u65f6\uff0c\u8bf7\u8003\u8651\u4ee5\u4e0b\u6700\u4f73\u505a\u6cd5\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u60a8\u53ef\u4ee5\u5c06\u8f7b\u91cf\u7ea7 DOM \u5b50\u7ec4\u4ef6\u5d4c\u5957\u5728\u7236\u9634\u5f71 DOM \u7ec4\u4ef6\u4e2d\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002<\/li>\n\n\n\n<li>\u6211\u4eec\u5efa\u8bae\u5c06\u6df1\u5ea6\u5d4c\u5957\u7684\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u5c01\u88c5\u5728\u9876\u5c42\u7684\u5355\u4e2a\u9634\u5f71 DOM \u7ec4\u4ef6\u4e2d\u3002\u7136\u540e\uff0c\u60a8\u53ef\u4ee5\u5728\u5f71\u5b50\u6839\u4e0b\u7684\u6240\u6709\u7ec4\u4ef6\u4e4b\u95f4\u5171\u4eab\u6837\u5f0f\u3002<\/li>\n\n\n\n<li>\u5728\u6587\u6863\u7ea7\u522b\u67e5\u8be2\u5143\u7d20\u6216\u6ce8\u5165\u6837\u5f0f\u65f6\u8981\u5c0f\u5fc3\u3002\u5f71\u5b50\u6811\u53ef\u4ee5\u4f4d\u4e8e\u6587\u6863\u548c\u7ec4\u4ef6\u4e4b\u95f4\u3002<\/li>\n\n\n\n<li>\u60a8\u53ef\u4ee5\u901a\u8fc7\u00a0CSS \u81ea\u5b9a\u4e49\u5c5e\u6027\u548c\u00a0\uff1a:p art\u00a0\u8986\u76d6\u9634\u5f71 DOM \u6837\u5f0f\u3002\u4f46\u662f\uff0c\u7ec4\u4ef6\u6240\u6709\u8005\u8d1f\u8d23\u516c\u5f00\u6269\u5c55\u70b9\uff0c\u8fd9\u53ef\u4ee5\u9632\u6b62\u4e0b\u6e38\u4f7f\u7528\u8005\u8bbe\u7f6e\u4efb\u610f\u5143\u7d20\u7684\u6837\u5f0f\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u54ea\u4e9b\u5185\u5bb9\u4e0d\u9002\u7528\u4e8e Light DOM<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e0d\u652f\u6301\u5c06\u8f7b\u91cf\u7ea7 DOM \u9650\u5236\u4e3a\u7279\u5b9a\u547d\u540d\u7a7a\u95f4\u3002<\/li>\n\n\n\n<li>\u4e0d\u652f\u6301\u5206\u53d1\u4ee5\u8f7b\u91cf\u7ea7 DOM \u6e32\u67d3\u7684\u7ec4\u4ef6\u3002\u6258\u7ba1\u5305\u4e2d\u7684\u7ec4\u4ef6\u5f15\u7528\u4f7f\u7528\u547d\u540d\u7a7a\u95f4\uff0c\u5e76\u4f1a\u5bfc\u81f4\u547d\u540d\u7a7a\u95f4\u51b2\u7a81\u3002<code>c<\/code><\/li>\n\n\n\n<li>\u57fa\u672c\u7ec4\u4ef6\u59cb\u7ec8\u5728\u5f71\u5b50 DOM \u4e2d\u5448\u73b0\u3002<\/li>\n\n\n\n<li>Aura \u7ec4\u4ef6\u4e0d\u80fd\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM\u3002\u4f46\u662f\uff0cAura \u7ec4\u4ef6\u53ef\u4ee5\u5305\u542b\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM \u7684 LWC \u7ec4\u4ef6\u3002<\/li>\n\n\n\n<li>\u63d2\u69fd\u4e0a\u7684\u751f\u547d\u5468\u671f\u6302\u94a9\u6c38\u8fdc\u4e0d\u4f1a\u88ab\u8c03\u7528\uff0c\u56e0\u4e3a\u8be5\u5143\u7d20\u4e0d\u4f1a\u5728 DOM \u4e2d\u5448\u73b0\u3002<code>slot<\/code><\/li>\n\n\n\n<li>\u4e0d\u652f\u6301\u5728\u8fed\u4ee3\u5668\u4e2d\u4f7f\u7528\u63d2\u69fd\u3002\u4f8b\u5982\uff1a<code>for:each<\/code><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- This results in a runtime error --&gt;\n&lt;template for:each={items} for:item=\"item\"&gt;\n  &lt;div key={item.id}&gt;\n    &lt;my-repeateditem item={item}&gt;\n      &lt;slot&gt;&lt;\/slot&gt;\n    &lt;\/my-repeateditem&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Lightning Locker \u6ce8\u610f\u4e8b\u9879<\/h2>\n\n\n\n<p>Lightning Locker\u00a0\u548c\u00a0Lightning Web Security\u00a0\u4e0d\u652f\u6301\u9876\u7ea7 light DOM \u7ec4\u4ef6\u3002Light DOM \u7ec4\u4ef6\u5e94\u59cb\u7ec8\u5d4c\u5957\u5728\u9634\u5f71 DOM \u7ec4\u4ef6\u4e2d\u7684\u67d0\u4e2a\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<p>\u7981\u7528 Locker\uff08\u4f8b\u5982\u5728 Experience Builder \u7ad9\u70b9\u4e2d\uff09\u610f\u5473\u7740\u60a8\u5c06\u65e0\u6cd5\u4ece Locker \u83b7\u5f97\u5b89\u5168\u4f18\u52bf\u3002\u786e\u4fdd\u60a8\u4e86\u89e3 Experience Builder \u7ad9\u70b9\u4e0a\u66f4\u5bbd\u677e\u7684 CSP \u73af\u5883\u7684\u540e\u679c\u3002\u8bf7\u53c2\u9605\u00a0CSP \u548c Lightning Locker \u8bbe\u8ba1\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n\n\n\n<p>\u5728\u57fa\u4e8e Aura \u7684 Experience Builder \u7ad9\u70b9\u4e2d\uff0cLightning Locker \u4f1a\u963b\u6b62 DOM \u8bbf\u95ee\u548c\u5176\u4ed6 Web API\u3002\u5982\u679c\u60a8\u5728\u57fa\u4e8e Aura \u7684 Experience Cloud \u7ad9\u70b9\u4e2d\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM\uff0c\u8bf7\u786e\u4fdd\u81f3\u5c11\u6709\u4e00\u4e2a LWC \u9634\u5f71 DOM \u7ec4\u4ef6\u4f5c\u4e3a\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u7684\u7956\u5148\u3002\u4f7f\u7528\u5f71\u5b50 DOM \u7ec4\u4ef6\u610f\u5473\u7740\u5c01\u88c5\u7ec4\u4ef6\u7684\u5185\u90e8\u6807\u8bb0\uff0c\u5e76\u53d7\u5230\u5f71\u5b50 DOM \u9650\u5236\u7684\u7ea6\u675f\u3002<code>this.querySelector()<\/code><\/p>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u4ece 23 \u5e74\u51ac\u5b63\u5f00\u59cb\uff0c\u5982\u679c\u5728\u7ec4\u7ec7\u4e2d\u542f\u7528\u4e86 Lightning Web Security \uff08LWS\uff09\uff0c\u5219 Aura \u7ad9\u70b9\u4e2d\u5305\u542b\u7684\u4efb\u4f55 Lightning Web \u7ec4\u4ef6\u90fd\u5c06\u53d7\u5230 LWS \u800c\u4e0d\u662f Lightning Locker \u7684\u4fdd\u62a4\u3002\u5982\u679c\u4e3a\u7ad9\u70b9\u7981\u7528 Lightning Locker\uff0c\u5219\u4e5f\u4f1a\u7981\u7528 Lightning Web Security\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6bd4\u8f83 Light DOM \u548c Shadow DOM<\/h2>\n\n\n\n<p>\u7531\u4e8e\u5176\u5f3a\u5927\u7684\u5c01\u88c5\u6027\uff0cshadow DOM \u662f\u521b\u4f5c\u7ec4\u4ef6\u7684\u63a8\u8350\u65b9\u6cd5\u3002\u5b83\u9690\u85cf\u4e86\u7ec4\u4ef6\u7684\u5185\u90e8\u7ed3\u6784\uff0c\u56e0\u6b64\u4f7f\u7528\u8005\u53ea\u80fd\u4f7f\u7528\u5176\u516c\u5171 API\u3002<\/p>\n\n\n\n<p>Shadow DOM \u4e0d\u9002\u7528\u4e8e\u4ee5\u4e0b\u60c5\u51b5\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6784\u5efa\u9ad8\u5ea6\u53ef\u81ea\u5b9a\u4e49\u7684 UI\uff0c\u5728\u5176\u4e2d\u5b8c\u5168\u63a7\u5236 Web \u5e94\u7528\u7684\u5916\u89c2\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u3002\u8bb8\u591a\u6d41\u884c\u7684\u5e93\u4e0e\u5f71\u5b50 DOM \u4e0d\u517c\u5bb9\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0cLight DOM \u66f4\u9002\u5408\uff0c\u4f46\u8bf7\u6ce8\u610f\uff0c\u6d88\u8d39\u8005\u53ef\u4ee5\u50cf\u4f7f\u7528\u516c\u5171 API \u4e00\u6837\u8bbf\u95ee\u7ec4\u4ef6\u7684\u5185\u90e8\u3002\u5141\u8bb8\u6b64\u7c7b\u8bbf\u95ee\u4f7f\u5f97\u5728\u4e0d\u5f71\u54cd\u4f7f\u7528\u8005\u4ee3\u7801\u7684\u60c5\u51b5\u4e0b\u5b9e\u73b0\u66f4\u6539\u53d8\u5f97\u5177\u6709\u6311\u6218\u6027\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u4f7f\u7528\u4e00\u4e2a\u800c\u4e0d\u662f\u53e6\u4e00\u4e2a\u7684\u5229\u5f0a\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>&nbsp;<\/th><th>\u5f71\u5b50 DOM<\/th><th>\u8f7b\u91cf\u7ea7 DOM<\/th><\/tr><\/thead><tbody><tr><td><strong>\u5b89\u5168<\/strong><\/td><td>\u5f3a\u5927\u7684\u7ec4\u4ef6\u5c01\u88c5\u53ef\u4fdd\u62a4\u7ec4\u4ef6\u514d\u53d7\u672a\u7ecf\u6388\u6743\u7684\u8bbf\u95ee<\/td><td>\u5f31\u5c01\u88c5\u4f7f\u7ec4\u4ef6\u5bb9\u6613\u53d7\u5230\u672a\u7ecf\u6388\u6743\u7684\u8bbf\u95ee<\/td><\/tr><tr><td><strong>\u53ef\u79fb\u690d\u6027<\/strong><\/td><td>\u9ad8\u5ea6\u53ef\u79fb\u690d\uff0c\u901a\u8fc7\u516c\u5171 API \u8fdb\u884c\u8bbf\u95ee\u63a7\u5236<\/td><td>\u5bb9\u6613\u53d7\u5230\u7ec4\u4ef6\u4f5c\u8005\u6216\u4f7f\u7528\u8005\u5bfc\u81f4\u7684\u91cd\u5927\u66f4\u6539\u7684\u5f71\u54cd<\/td><\/tr><tr><td><strong>\u9020\u578b<\/strong><\/td><td>\u9700\u8981 CSS \u81ea\u5b9a\u4e49\u5c5e\u6027\u6765\u8986\u76d6\u6837\u5f0f<\/td><td>\u6613\u4e8e\u8986\u76d6\u6837\u5f0f<\/td><\/tr><tr><td><strong>\u7b2c\u4e09\u65b9\u5e93\u548c\u5de5\u5177\u96c6\u6210<\/strong><\/td><td>\u4e0e\u9700\u8981 DOM \u904d\u5386\u6216\u4e8b\u4ef6\u91cd\u5b9a\u5411\u7684\u7b2c\u4e09\u65b9\u5e93\u6216\u5de5\u5177\u7684\u517c\u5bb9\u6027\u6709\u9650<\/td><td>\u4e0e\u7b2c\u4e09\u65b9\u5e93\u548c\u5de5\u5177\u7684\u7b80\u5355\u96c6\u6210<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\uff08\u4f8b\u5982 Google Analytics \u6216\u5176\u4ed6\u68c0\u6d4b\u5e93\uff09\u65f6\uff0c\u5982\u679c\u60a8\u7684\u5f71\u5b50 DOM \u7ec4\u4ef6\u516c\u5f00\u4e86\u6b63\u786e\u7684 API\uff0c\u5219\u4e0d\u5fc5\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM\u3002\u5047\u8bbe\u60a8\u8981\u68c0\u6d4b\u6309\u94ae\u4e0a\u7684\u70b9\u51fb\u4ea4\u4e92\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- myButton.html example --&gt;\n&lt;template&gt;\n  &lt;button&gt;{label}&lt;\/button&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528 light DOM\uff0c\u60a8\u53ef\u4ee5\u5728\u5143\u7d20\u4e0a\u9644\u52a0\u5355\u51fb\u4e8b\u4ef6\u4fa6\u542c\u5668\u3002\u5982\u679c\u5728\u9634\u5f71 DOM \u4e2d\u6e32\u67d3\u7ec4\u4ef6\uff0c\u5219\u65e0\u6cd5\u4ece\u7ec4\u4ef6\u5916\u90e8\u8bbf\u95ee\u8be5\u5143\u7d20\u3002\u4f7f\u7528\u5f71\u5b50 DOM\uff0c\u6210\u4e3a\u7ec4\u4ef6\u7684\u5185\u90e8\u5b9e\u73b0\u7ec6\u8282\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u68c0\u6d4b\u6b64\u7ec4\u4ef6\u7684\u6b63\u786e\u65b9\u6cd5\u662f\u5728\u5176\u81ea\u8eab\u4e0a\u6dfb\u52a0\u4e00\u4e2a\u5355\u51fb\u5904\u7406\u7a0b\u5e8f\u6765\u68c0\u6d4b\u5b83\u3002<code>button<\/code><code>button<\/code><code>&lt;button&gt;<\/code><code>my-button<\/code><code>my-button<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- myComponent.html example --&gt;\n&lt;template&gt;\n  &lt;my-button label=\"click me\" onclick={handleClick}&gt;&lt;\/my-button&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u4ec5\u516c\u5f00\u8981\u68c0\u6d4b\u7684\u6700\u4f4e\u9650\u5ea6\uff0c\u56e0\u4e3a\u516c\u5f00\u5185\u90e8\u4e8b\u4ef6\u4f1a\u524a\u5f31\u7ec4\u4ef6\u7684\u5c01\u88c5\u3002\u867d\u7136\u4e0a\u8ff0\u793a\u4f8b\u5e76\u975e\u59cb\u7ec8\u53ef\u884c\uff0c\u4f46\u6211\u4eec\u5efa\u8bae\u60a8\u5728\u9009\u62e9\u6700\u9002\u5408\u60a8\u7684\u7528\u4f8b\u7684\u9009\u9879\u4e4b\u524d\u63a2\u7d22\u60a8\u7684\u9009\u9879\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5728\u7ec4\u4ef6\u4e2d\u542f\u7528\u8f7b\u91cf\u7ea7 DOM<\/h2>\n\n\n\n<p>\u8981\u542f\u7528\u8f7b\u91cf\u7ea7 DOM\uff0c\u9996\u5148\u5728\u7ec4\u4ef6\u7c7b\u4e2d\u8bbe\u7f6e static \u5c5e\u6027\uff1a<code>renderMode<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { LightningElement } from \"lwc\";\n\nexport default class LightDomApp extends LightningElement {\n  static renderMode = \"light\"; \/\/ the default is 'shadow'\n}<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u4f7f\u7528\u6839\u6a21\u677f\u6307\u4ee4\uff0c\u8fd9\u662f\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM \u7684\u7ec4\u4ef6\u6240\u5fc5\u9700\u7684\u3002<code>lwc:render-mode<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template lwc:render-mode=\"light\"&gt;\n  &lt;my-header&gt;\n    &lt;p&gt;Hello World&lt;\/p&gt;\n  &lt;\/my-header&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u5b9e\u4f8b\u5316\u540e\u66f4\u6539\u9759\u6001\u5c5e\u6027\u7684\u503c\u4e0d\u4f1a\u5f71\u54cd\u7ec4\u4ef6\u662f\u5728\u8f7b\u91cf\u7ea7 DOM \u8fd8\u662f\u9634\u5f71 DOM \u4e2d\u5448\u73b0\u3002<code>renderMode<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u7528 Light DOM<\/h2>\n\n\n\n<p>\u5c06\u7ec4\u4ef6\u4ece\u5f71\u5b50 DOM \u8fc1\u79fb\u5230\u8f7b\u91cf\u7ea7 DOM \u9700\u8981\u4e00\u4e9b\u4ee3\u7801\u66f4\u6539\u3002\u5f71\u5b50\u6811\u4f1a\u5f71\u54cd\u60a8\u4f7f\u7528 CSS\u3001\u4e8b\u4ef6\u548c DOM \u7684\u65b9\u5f0f\u3002\u5728\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM \u65f6\uff0c\u8bf7\u8003\u8651\u4ee5\u4e0b\u5404\u8282\u4e2d\u63cf\u8ff0\u7684\u5dee\u5f02\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7ec4\u6210<\/h2>\n\n\n\n<p>\u60a8\u7684\u5e94\u7528\u53ef\u4ee5\u5305\u542b\u4f7f\u7528\u9634\u5f71\u6216\u6d45\u8272 DOM \u7684\u7ec4\u4ef6\u3002\u5728\u6b64\u793a\u4f8b\u6a21\u677f\u4e2d\uff0c\u4f7f\u7528\u5f71\u5b50 DOM \u5e76\u5305\u542b\u591a\u4e2a\u7ec4\u4ef6\uff1a\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM \u548c\u4f7f\u7528\u5f71\u5b50 DOM\u3002<code>my-app<\/code><code>my-header<\/code><code>my-footer<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;my-app&gt;\n  #shadow-root \n  | &lt;my-header&gt;\n  |   &lt;p&gt;Hello World&lt;\/p&gt;\n  | &lt;\/my-header&gt;\n  | &lt;my-footer&gt;\n  |   #shadow-root \n  |   |  &lt;p&gt;Footer&lt;\/p&gt;\n  | &lt;\/my-footer&gt;\n&lt;\/my-app&gt;<\/code><\/pre>\n\n\n\n<p>\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u53ef\u4ee5\u5305\u542b\u9634\u5f71 DOM \u7ec4\u4ef6\u3002\u7c7b\u4f3c\u5730\uff0c\u5f71\u5b50 DOM \u7ec4\u4ef6\u53ef\u4ee5\u5305\u542b\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u3002<\/p>\n\n\n\n<p>\u63d0\u793a<\/p>\n\n\n\n<p>\u5982\u679c\u60a8\u6709\u6df1\u5ea6\u5d4c\u5957\u7684\u7ec4\u4ef6\uff0c\u8bf7\u8003\u8651\u5728\u9876\u5c42\u4f7f\u7528\u5d4c\u5957\u7684\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u7684\u5355\u4e2a\u9634\u5f71 DOM \u7ec4\u4ef6\u3002\u6b64\u7ed3\u6784\u5141\u8bb8\u60a8\u5728\u4e00\u4e2a\u5f71\u5b50\u6839\u4e2d\u7684\u6240\u6709\u5b50\u7ec4\u4ef6\u4e4b\u95f4\u81ea\u7531\u5171\u4eab\u6837\u5f0f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u53ef\u53ca\u6027<\/h2>\n\n\n\n<p>\u4e0e\u5408\u6210\u9634\u5f71\u6216\u539f\u751f\u9634\u5f71\u4e0d\u540c\uff0clight DOM \u4e0d\u4f1a\u5c06 ID \u8303\u56f4\u9650\u5b9a\u4e3a\u5355\u4e2a\u7ec4\u4ef6\u3002\u76f8\u53cd\uff0c\u5b83\u4f7f\u7ec4\u4ef6\u80fd\u591f\u5f15\u7528\u5355\u72ec\u7ec4\u4ef6\u4e0a\u7684 ID\u3002\u8fd9\u4e00\u4f18\u70b9\u4f7f\u60a8\u80fd\u591f\u4f7f\u7528 ID \u548c ARIA \u5c5e\u6027\u5c06\u4e24\u4e2a\u5143\u7d20\u653e\u5728\u540c\u4e00\u4e2a\u5f71\u5b50\u6839\u4e2d\u6765\u94fe\u63a5\u5b83\u4eec\u3002<\/p>\n\n\n\n<p>\u8bf7\u8003\u8651\u6b64\u793a\u4f8b\uff0c\u5176\u4e2d\u5305\u542b\u4e24\u4e2a\u540c\u7ea7\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- container.html --&gt;\n&lt;template&gt;\n  &lt;c-label&gt;&lt;\/c-label&gt;\n  &lt;c-input&gt;&lt;\/c-input&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u8be5\u7ec4\u4ef6\u5305\u542b\u4e00\u4e2a\u5177\u6709\u5c5e\u6027\u7684\u5143\u7d20\u3002<code>c-label<\/code><code>&lt;label&gt;<\/code><code>id<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- label.html --&gt;\n&lt;template lwc:render-mode=\"light\"&gt;\n  &lt;label id=\"my-label\"&gt;My label&lt;\/label&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u8be5\u7ec4\u4ef6\u5305\u542b\u4e00\u4e2a\u5143\u7d20\uff0c\u8be5\u5143\u7d20\u5f15\u7528\u7ec4\u4ef6\u4e2d\u7684\u5143\u7d20\u3002<code>c-input<\/code><code>&lt;input&gt;<\/code><code>&lt;label&gt;<\/code><code>c-label<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- input.html --&gt;\n&lt;template lwc:render-mode=\"light\"&gt;\n  &lt;input type=\"text\" aria-labelledby=\"my-label\" \/&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">CSS\u7684<\/h2>\n\n\n\n<p>\u4f7f\u7528\u5f71\u5b50 DOM \u65f6\uff0c\u5728\u7236\u7ec4\u4ef6\u4e2d\u5b9a\u4e49\u7684 CSS \u6837\u5f0f\u4e0d\u9002\u7528\u4e8e\u5b50\u7ec4\u4ef6\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u8f7b\u91cf\u7ea7 DOM \u5141\u8bb8\u4ece\u6839\u6587\u6863\u8bbe\u7f6e\u6837\u5f0f\u4ee5\u9488\u5bf9 DOM \u8282\u70b9\u5e76\u8bbe\u7f6e\u5176\u6837\u5f0f\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u672c\u673a\u9634\u5f71\u7ec4\u4ef6\u4e0a\u7684\u6837\u5f0f\u7ea7\u8054\u5230\u5b50\u7ec4\u4ef6\u7684\u6d45\u8272 DOM \u4e2d\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0clight DOM \u7ec4\u4ef6\u4f4d\u4e8e\u539f\u751f\u9634\u5f71\u7ec4\u4ef6\u4e2d\uff0c\u5e76\u6302\u8f7d\u5728\u6700\u8fd1\u7684\u539f\u751f\u9634\u5f71\u6839\u7ea7\u522b\uff0c\u8be5\u6839\u7ea7\u522b\u5728\u672c\u5730\u4f5c\u7528\u57df\u4e3a\u6574\u4e2a\u9634\u5f71\u6839\uff0c\u5e76\u5f71\u54cd\u8be5\u6839\u5185\u7684\u4efb\u4f55\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n  &lt;my-app&gt;\n    #shadow-root\n    |  &lt;style&gt; p { color: green; }&lt;\/style&gt;\n    |  &lt;p&gt;This is a paragraph in shadow DOM&lt;\/p&gt;\n    |    &lt;my-container&gt;\n    |      &lt;p&gt;This is a paragraph in light DOM&lt;\/p&gt;\n    |    &lt;\/my-container&gt;\n  &lt;\/my-app&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u540c\u6837\uff0c\u5728\u8f7b\u91cf\u7ea7 DOM \u4e2d\u5448\u73b0\u7684\u5b50\u7ec4\u4ef6\u4e0a\u7684\u6837\u5f0f\u5c06\u5e94\u7528\u4e8e\u5176\u7236\u7ec4\u4ef6\uff0c\u76f4\u5230\u5728\u4f7f\u7528\u672c\u673a\u9634\u5f71 DOM \u65f6\u9047\u5230\u9634\u5f71\u8fb9\u754c\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u5408\u6210\u9634\u5f71 DOM\uff0c\u9634\u5f71 DOM \u6837\u5f0f\u4e0d\u4f1a\u7ea7\u8054\u5230\u8f7b\u91cf\u7ea7 DOM \u5b50\u7ec4\u4ef6\u4e2d\u3002<\/p>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u5728\u5408\u6210\u5f71\u5b50 DOM \u4e2d\uff0c\u6837\u5f0f\u662f\u5728\u5168\u5c40\u6587\u6863\u7ea7\u522b\u5b9e\u73b0\u7684\uff0c\u4f46\u4f7f\u7528\u5c5e\u6027\u6765\u9650\u5b9a\u6837\u5f0f\u7684\u8303\u56f4\u3002\u8fd9\u662f\u5408\u6210\u5f71\u5b50 DOM \u7684\u5f53\u524d\u9650\u5236\u3002<\/p>\n\n\n\n<p>LWC \u4e0d\u4f1a\u81ea\u52a8\u4e3a\u60a8\u786e\u5b9a\u6837\u5f0f\u8303\u56f4\u3002\u4e3a\u4e86\u9632\u6b62\u6837\u5f0f\u4ece\u7ec4\u4ef6\u4e2d\u7ea7\u8054\u51fa\u6765\uff0c\u6211\u4eec\u5efa\u8bae\u5bf9\u6587\u4ef6\u4f7f\u7528\u4f5c\u7528\u57df\u6837\u5f0f\u3002\u8bf7\u53c2\u9605<strong>\u5728 Light DOM \u4e2d\u4f7f\u7528\u4f5c\u7528\u57df\u6837\u5f0f<\/strong>\u90e8\u5206\u3002<code>*.scoped.css<\/code><\/p>\n\n\n\n<p>\u8981\u8986\u76d6 Lightning Web \u7ec4\u4ef6\u4e2d\u7ee7\u627f\u7684\u6837\u5f0f\uff0c\u8bf7\u5728\u7ec4\u4ef6\u6837\u5f0f\u8868\u4e2d\u521b\u5efa\u00a0SLDS \u6837\u5f0f\u6302\u94a9\u3002\u6837\u5f0f\u6302\u94a9\u5145\u5f53\u81ea\u5b9a\u4e49\u6837\u5f0f\u7684\u5360\u4f4d\u7b26\u3002\u6709\u5173\u652f\u6301\u6837\u5f0f\u6302\u94a9\u7684\u7ec4\u4ef6\u84dd\u56fe\u5217\u8868\uff0c\u8bf7\u53c2\u9605\u84dd\u56fe\u6982\u8ff0\u3002<\/p>\n\n\n\n<p>\u63d0\u793a<\/p>\n\n\n\n<p>\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u7684\u6e32\u67d3\u987a\u5e8f\u4f1a\u5f71\u54cd\u6837\u5f0f\u8868\u6ce8\u5165\u6839\u8282\u70b9\u7684\u987a\u5e8f\uff0c\u5e76\u76f4\u63a5\u5f71\u54cd CSS \u89c4\u5219\u7684\u7279\u5f02\u6027\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u8bbf\u95ee\u5143\u7d20<\/h2>\n\n\n\n<p>\u5728\u5f71\u5b50 DOM \u4e2d\uff0c\u60a8\u53ea\u80fd\u8bbf\u95ee\u7ec4\u4ef6\u62e5\u6709\u7684\u5143\u7d20\u3002<\/p>\n\n\n\n<p>\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u60a8\u53ef\u4ee5\u4ece\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u4e2d\u68c0\u7d22\u8282\u70b9\uff0c\u8fd9\u5bf9\u7b2c\u4e09\u65b9\u96c6\u6210\u548c\u6d4b\u8bd5\u5f88\u6709\u5e2e\u52a9\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 \u67e5\u8be2\u5e94\u7528\u4e2d\u7684\u6bb5\u843d\u3002<code>document.querySelector('p')<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- JS code returns \"Your Content Here\" --&gt;\n&lt;template&gt;\n  &lt;script&gt;\n    console.log(document.querySelector(\"my-custom-class\").textContent);\n  &lt;\/script&gt;\n  &lt;my-component&gt;\n    &lt;div class=\"my-custom-class\"&gt;Your Content Here&lt;\/div&gt;\n  &lt;\/my-component&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528 shadow DOM \u65f6\uff0c\u8fd4\u56de\u4e0e\u7ec4\u4ef6\u5173\u8054\u7684\u5f71\u5b50\u6839\u3002\u8be5\u5143\u7d20\u4e0d\u9002\u7528\u4e8e\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM \u7684\u7ec4\u4ef6\uff0c\u56e0\u6b64\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM \u65f6\uff0c\u8fd4\u56de .<code>LightningElement.prototype.template<\/code><code>template<\/code><code>LightningElement.prototype.template<\/code><code>null<\/code><\/p>\n\n\n\n<p>\u5c06\u5f71\u5b50 DOM \u7ec4\u4ef6\u8fc1\u79fb\u5230\u8f7b\u578b DOM \u65f6\uff0c\u8bf7\u66ff\u6362\u4e3a .\u4ee5\u4e0b\u793a\u4f8b\u4f7f\u7528\u5e38\u89c1 DOM API \u5217\u8868\u6765\u5904\u7406\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u3002<code>this.template.querySelector<\/code><code>this.querySelector<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { LightningElement } from \"lwc\";\n\nexport default class LightDomApp extends LightningElement {\n  static renderMode = \"light\";\n  query(event) {\n    const el = this.querySelector(\"p\");\n    const all = this.querySelectorAll(\"p\");\n    const elById = this.getElementById(\"#myId\");\n    const elements = this.getElementsByClassName(\"my-class\");\n    const tag = this.getElementsByTagName(\"button\");\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\uff0c\u53ef\u4ee5\u8fd4\u56de\u5176\u4ed6\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u6e32\u67d3\u7684\u5143\u7d20\u3002<code>this.querySelectorAll()<\/code><\/p>\n\n\n\n<p>\u5143\u7d20\u7684\u00a0id\u00a0\u5c5e\u6027\u5728\u8fd0\u884c\u65f6\u4fdd\u7559\uff0c\u4e0d\u4f1a\u50cf\u5728\u5408\u6210\u5f71\u5b50 DOM \u4e2d\u90a3\u6837\u4f5c\u3002\u56e0\u6b64\uff0c\u60a8\u53ef\u4ee5\u5728 CSS \u6216 JavaScript \u4e2d\u4f7f\u7528\u9009\u62e9\u5668\uff0c\u56e0\u4e3a\u5b83\u4e0e\u8fd0\u884c\u65f6\u7684\u5143\u7d20\u5339\u914d\u3002<code>idid<\/code><\/p>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u6216\u8005\uff0c\u5728\u5904\u7406\u8f7b\u91cf\u7ea7 DOM \u548c\u9634\u5f71 DOM \u4e2d\u7684\u7ec4\u4ef6\u65f6\uff0c\u8bf7\u4f7f\u7528\u00a0<code>this.refs<\/code>\u3002 \u8bbf\u95ee\u7ec4\u4ef6\u4e2d\u5b9a\u4e49\u7684\u5143\u7d20\uff0c\u5e76\u4e14\u5728 light DOM \u548c shadow DOM \u4e2d\u7684\u884c\u4e3a\u7c7b\u4f3c\uff0c\u8fd9\u4e0e or \u4e0d\u540c\u3002<code>this.refsthis.querySelectorthis.querySelectorAll<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8b\u4ef6<\/h2>\n\n\n\n<p>\u4f7f\u7528 shadow DOM \u65f6\uff0c\u5982\u679c\u4e8b\u4ef6\u5192\u6ce1\u5e76\u8d8a\u8fc7\u5f71\u5b50\u8fb9\u754c\uff0c\u5219\u67d0\u4e9b\u5c5e\u6027\u503c\u4f1a\u66f4\u6539\u4ee5\u5339\u914d\u4fa6\u542c\u5668\u7684\u4f5c\u7528\u57df\u3002\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM \u65f6\uff0c\u4e8b\u4ef6\u4e0d\u4f1a\u88ab\u91cd\u5b9a\u5411\u3002\u5982\u679c\u5355\u51fb\u5d4c\u5957\u5728\u591a\u4e2a\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u5c42\u4e2d\u7684\u6309\u94ae\uff0c\u5219\u53ef\u4ee5\u5728\u6587\u6863\u7ea7\u522b\u8bbf\u95ee\u8be5\u4e8b\u4ef6\u3002\u6b64\u5916\uff0c\u8fd4\u56de\u89e6\u53d1\u4e8b\u4ef6\u7684\u6309\u94ae\uff0c\u800c\u4e0d\u662f\u5305\u542b\u7684\u7ec4\u4ef6\u3002<code>click<\/code><code>event.target<\/code><\/p>\n\n\n\n<p>\u4f8b\u5982\uff0c\u4f60\u6709\u4e00\u4e2a\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM \u7684\u7ec4\u4ef6\uff0c\u8be5\u7ec4\u4ef6\u5d4c\u5957\u5728\u4e00\u4e2a\u540c\u6837\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM \u7684\u5bb9\u5668\u7ec4\u4ef6\u4e2d\u3002\u9876\u7ea7\u7ec4\u4ef6\u4f7f\u7528\u5f71\u5b50 DOM\u3002<code>c-light-child<\/code><code>c-light-container<\/code><code>c-app<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- app.html (shadow DOM) --&gt;\n&lt;template&gt;\n  &lt;c-light-container onbuttonclick={handleButtonClick}&gt; &lt;\/c-light-container&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- lightContainer.html --&gt;\n&lt;template lwc:render-mode=\"light\"&gt;\n  &lt;p&gt;Hello, Light DOM Container&lt;\/p&gt;\n  &lt;!-- c-light-child host --&gt;\n  &lt;c-light-child onbuttonclick={handleButtonClick}&gt; &lt;\/c-light-child&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ lightContainer.js\nimport { LightningElement } from \"lwc\";\n\nexport default class LightContainer extends LightningElement {\n  static renderMode = \"light\";\n  handleButtonClick(event) {\n    \/\/ do something\n  }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- lightChild.html --&gt;\n&lt;template lwc:render-mode=\"light\"&gt;\n  &lt;button onclick={handleClick}&gt;&lt;\/button&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ lightChild.js\nimport { LightningElement } from \"lwc\";\n\nexport default class LightChild extends LightningElement {\n  static renderMode = \"light\";\n  handleClick(event) {\n    this.dispatchEvent(new CustomEvent(\"buttonclick\", { bubbles: true, composed: false }));\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u5f53\u60a8\u8c03\u5ea6 \u4e2d\u7684\u81ea\u5b9a\u4e49\u4e8b\u4ef6\u65f6\uff0c\u5904\u7406\u7a0b\u5e8f\u5c06\u8fd4\u56de\u4ee5\u4e0b\u5143\u7d20\u3002<code>buttonclick<\/code><code>c-light-child<\/code><\/p>\n\n\n\n<p><code>c-light-child<\/code>\u4e3b\u673a\u5904\u7406\u7a0b\u5e8f<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>event.currentTarget<\/code>:<code>c-light-child<\/code><\/li>\n\n\n\n<li><code>event.target<\/code>:<code>c-light-child<\/code><\/li>\n<\/ul>\n\n\n\n<p><code>c-light-container<\/code>\u4e3b\u673a\u5904\u7406\u7a0b\u5e8f<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>event.currentTarget<\/code>:<code>c-light-container<\/code><\/li>\n\n\n\n<li><code>event.target<\/code>:<code>c-light-child<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u76f8\u53cd\uff0c\u5982\u679c\u4f7f\u7528\u5f71\u5b50 DOM\uff0c\u5219\u4e8b\u4ef6\u4e0d\u4f1a\u8f6c\u4e49\u5f71\u5b50\u6839\u3002<code>c-light-container<\/code><\/p>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u5373\u4f7f\u5728\u8f7b\u91cf\u7ea7 DOM \u4e2d\uff0c\u4e8b\u4ef6\u4e5f\u4f1a\u901a\u8fc7\u7ec4\u4ef6\u5192\u6ce1\uff0c\u56e0\u4e3a\u6ca1\u6709\u5f71\u5b50\u6839\u3002<code>composed<\/code><code>false<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u63d2\u69fd<\/h2>\n\n\n\n<p>\u63d2\u69fd\u662f\u5728\u8f7b\u91cf\u7ea7 DOM \u4e2d\u6a21\u62df\u7684\uff0c\u56e0\u4e3a\u6d4f\u89c8\u5668\u4e0d\u652f\u6301 shadow DOM \u4e4b\u5916\u7684\u63d2\u69fd\u3002LWC \u5728\u8fd0\u884c\u65f6\u786e\u5b9a\u63d2\u69fd\u662f\u5426\u5728\u8f7b\u91cf\u7ea7 DOM \u4e0a\u8fd0\u884c\u3002<\/p>\n\n\n\n<p>\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u5177\u6709\u547d\u540d\u548c\u672a\u547d\u540d\u63d2\u69fd\u7684\u7ec4\u4ef6\u3002<code>my-component<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- myComponent.html --&gt;\n&lt;template&gt;\n  &lt;slot name=\"title\"&gt;&lt;\/slot&gt;\n  &lt;h3&gt;Subtitle&lt;\/h3&gt;\n  &lt;slot&gt;&lt;\/slot&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u50cf\u8fd9\u6837\u4f7f\u7528\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;my-component&gt;\n  &lt;p&gt;Default slotted content&lt;\/p&gt;\n  &lt;h1 slot=\"title\"&gt;Component Title&lt;\/h1&gt;\n&lt;\/my-component&gt;<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e9b\u5143\u7d20\u4e0d\u4f1a\u5448\u73b0\u5230 DOM\u3002\u5185\u5bb9\u76f4\u63a5\u9644\u52a0\u5230 DOM \u4e2d\u7684 host \u5143\u7d20\u3002<code>&lt;slot&gt;<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;my-component&gt;\n  &lt;h1&gt;Component Title&lt;\/h1&gt;\n  &lt;h3&gt;Subtitle&lt;\/h3&gt;\n  &lt;p&gt;Default slotted content&lt;\/p&gt;\n&lt;\/my-component&gt;<\/code><\/pre>\n\n\n\n<p>\u5728\u8fd0\u884c\u65f6\uff0c\u63d2\u69fd\u5185\u5bb9\u6216\u56de\u9000\u5185\u5bb9\u5c06\u5e73\u5c55\u5230\u7236\u5143\u7d20\u3002\u5143\u7d20\u672c\u8eab\u4e0d\u4f1a\u5448\u73b0\uff0c\u56e0\u6b64\u5411\u5143\u7d20\u6dfb\u52a0\u5c5e\u6027\u6216\u4e8b\u4ef6\u4fa6\u542c\u5668\u4f1a\u5f15\u53d1\u7f16\u8bd1\u5668\u9519\u8bef\u3002<code>&lt;slot&gt;<\/code><code>&lt;slot&gt;<\/code><\/p>\n\n\n\n<p>\u6b64\u5916\uff0c\u8bf7\u8003\u8651\u8fd9\u4e2a\u5305\u542b\u9634\u5f71 DOM \u7ec4\u4ef6\u548c\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u7684\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u3002<code>c-light-slot-consumer<\/code><code>c-shadow-slot-container<\/code><code>c-light-slot-container<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- app.html --&gt;\n&lt;template&gt;\n  &lt;c-shadow-component&gt;&lt;\/c-shadow-component&gt;\n  &lt;c-light-slot-consumer&gt;&lt;\/c-light-slot-consumer&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- lightSlotConsumer.html --&gt;\n&lt;template lwc:render-mode=\"light\"&gt;\n  &lt;c-shadow-slot-container&gt;\n    &lt;p&gt;Hello from shadow slot&lt;\/p&gt;\n  &lt;\/c-shadow-slot-container&gt;\n  &lt;c-light-slot-container&gt;\n    &lt;p&gt;Hello from light slot&lt;\/p&gt;\n  &lt;\/c-light-slot-container&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- shadowSlotContainer.html --&gt;\n&lt;template&gt;\n  &lt;slot&gt;&lt;\/slot&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- lightSlotContainer.html --&gt;\n&lt;template lwc:render-mode=\"light\"&gt;\n  &lt;slot name=\"other\"&gt;\n    &lt;p&gt;Hello from other slot&lt;\/p&gt;\n  &lt;\/slot&gt;\n  &lt;slot&gt;This is the default slot&lt;\/slot&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u5728 \u4e2d\u5305\u542b\u6837\u5f0f\uff0c<em>\u5219\u63d2\u69fd\u4e2d\u7684\u6240\u6709<\/em>\u5143\u7d20\uff08\u5728\u9634\u5f71 DOM \u548c\u6d45\u8272 DOM \u7ec4\u4ef6\u4e2d\uff09\u90fd\u4f1a\u83b7\u5f97\u6837\u5f0f\u3002\u4f46\u662f\uff0c<em>\u6ca1\u6709\u63d2\u69fd\u7684\u5f71\u5b50 DOM \u7ec4\u4ef6\u4e0d\u4f1a<\/em>\u63a5\u6536\u6837\u5f0f\u3002<code>c-app<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;c-app&gt;\n  &lt;style type=\"text\/css\"&gt;\n    p {\n      background: green;\n      color: white;\n    }\n  &lt;\/style&gt;    \n  &lt;h2&gt;Hello Light DOM&lt;\/h2&gt;\n    &lt;p&gt;This is a paragraph in app.html&lt;\/p&gt;\n    &lt;h3&gt;Shadow DOM&lt;\/h3&gt;\n    &lt;c-shadow-component&gt;\n        #shadow-root (open)\n        | &lt;p&gt;Hello, Shadow DOM container&lt;\/p&gt;\n    &lt;\/c-shadow-component&gt;\n    &lt;h3&gt;Slots&lt;\/h3&gt;\n    &lt;c-light-slot-consumer&gt;\n        &lt;c-shadow-slot-container&gt;\n            #shadow-root (open)\n            | &lt;p&gt;Hello from shadow-slot-container&lt;\/p&gt;\n        &lt;\/c-shadow-slot-container&gt;\n        &lt;c-light-slot-container&gt;\n            &lt;p&gt;Hello from other slot&lt;\/p&gt;\n            &lt;p&gt;Hello from light-slot-container&lt;\/p&gt;\n        &lt;\/c-light-slot-container&gt;\n    &lt;\/c-light-slot-consumer&gt;\n&lt;\/c-app&gt;<\/code><\/pre>\n\n\n\n<p>\u8003\u8651\u4f7f\u7528\u63d2\u69fd\u7684\u8fd9\u4e9b\u7ec4\u5408\u6a21\u578b\u3002\u8f7b\u91cf\u7ea7 DOM \u4e2d\u7684\u7ec4\u4ef6\u53ef\u4ee5\u63d2\u5165\u5185\u5bb9\u548c\u5176\u4ed6\u7ec4\u4ef6\u3002\u63d2\u69fd\u652f\u6301\u8f7b\u91cf\u7ea7 DOM \u548c\u9634\u5f71 DOM \u7ec4\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n  &lt;slot name=\"content\"&gt;Default content in the named slot&lt;\/slot&gt;\n  &lt;p&gt;This makes the component a bit more complex&lt;\/p&gt;\n  &lt;slot&gt;This is a default slot to test if content bypasses the named slot and goes here&lt;\/slot&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u60a8\u7684\u5185\u5bb9\u5728\u63d2\u69fd\u4e2d\u7684\u5448\u73b0\u65b9\u5f0f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;my-component&gt;\n  &lt;!-- Inserted into the content slot --&gt;\n  &lt;div slot=\"content\"&gt;Some text here&lt;\/div&gt;\n&lt;\/my-component&gt;\n\n&lt;my-component&gt;\n  &lt;!-- Inserted into the content slot --&gt;\n  &lt;my-shadow-lwc slot=\"content\"&gt;Some text here&lt;\/my-shadow-lwc&gt;\n&lt;\/my-component&gt;\n\n&lt;my-component&gt;\n  &lt;!-- Inserted into the content slot --&gt;\n  &lt;my-light-lwc slot=\"content\"&gt;Some text here&lt;\/my-light-lwc&gt;\n&lt;\/my-component&gt;\n\n&lt;my-component&gt;\n  &lt;!-- Inserted into the default slot --&gt;\n  &lt;my-shadow-lwc&gt;Some text here&lt;\/my-shadow-lwc&gt;\n&lt;\/my-component&gt;\n\n&lt;my-component&gt;\n  &lt;!-- Inserted into the default slot --&gt;\n  &lt;my-light-lwc&gt;Some text here&lt;\/my-light-lwc&gt;\n&lt;\/my-component&gt;<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u4e0d\u652f\u6301\u4e8b\u4ef6\u548c CSS \u4f2a\u9009\u62e9\u5668\uff0c\u56e0\u4e3a slot \u5143\u7d20\u4e0d\u4f1a\u5728 DOM \u4e2d\u5448\u73b0\u3002<code>slotchange<\/code><code>::slotted<\/code><\/p>\n\n\n\n<p>Light DOM \u4e0d\u4f1a\u6e32\u67d3\u672a\u5206\u914d\u7ed9\u63d2\u69fd\u7684\u63d2\u69fd\u5143\u7d20\uff0c\u56e0\u6b64\u6c38\u8fdc\u4e0d\u4f1a\u8c03\u7528\u5b83\u4eec\u7684\u751f\u547d\u5468\u671f\u94a9\u5b50\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c-parent --&gt;\n&lt;template&gt;\n  &lt;c-child&gt;\n    &lt;span&gt;This element is not rendered in light DOM&lt;\/span&gt;\n  &lt;\/c-child&gt;\n&lt;\/template&gt;\n\n&lt;!-- c-child --&gt;\n&lt;template&gt;\n  &lt;p&gt;This component does not include a slot&lt;\/p&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f5c\u7528\u57df\u63d2\u69fd<\/h2>\n\n\n\n<p>\u4f7f\u7528\u4f5c\u7528\u57df\u69fd\uff0c\u60a8\u53ef\u4ee5\u8bbf\u95ee\u5b50\u7ec4\u4ef6\u4e2d\u7684\u6570\u636e\uff0c\u5e76\u5728\u7236\u7ec4\u4ef6\u5185\u7684\u69fd\u5185\u5bb9\u4e2d\u5448\u73b0\u6570\u636e\u3002\u901a\u8fc7\u5c06\u6570\u636e\u4ece\u5b50\u7ec4\u4ef6\u7ed1\u5b9a\u5230\u4f5c\u7528\u57df\u5185\u63d2\u69fd\uff0c\u7236\u7ec4\u4ef6\u53ef\u4ee5\u5728\u63d2\u69fd\u5185\u5bb9\u4e2d\u5f15\u7528\u5b50\u7ec4\u4ef6\u7684\u6570\u636e\u3002\u6b64\u6570\u636e\u5165\u5b50\u7ec4\u4ef6\u7684\u8f7b\u91cf\u7ea7 DOM \u4e2d\u3002<\/p>\n\n\n\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u5b50\u7ec4\u4ef6\u5c06\u5176\u6570\u636e\u7ed1\u5b9a\u5230\u4f5c\u7528\u57df\u69fd\u3002\u5728\u7236\u7ec4\u4ef6\u4e2d\uff0c\u4f5c\u7528\u57df\u5185\u7684\u69fd\u7247\u6bb5\u5f15\u7528\u4ee5\u53ca\u5c06\u69fd\u5165\u7684\u6807\u8bb0\u3002<code>&lt;c-child&gt;<\/code><code>item<\/code><code>&lt;slot&gt;<\/code><code>&lt;c-parent&gt;<\/code><code>{item.id}<\/code><code>{item.name}<\/code><code>&lt;c-child&gt;<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c\/parent.html --&gt;\n&lt;template&gt; &lt;!-- Parent component doesn\u2019t need to be light DOM --&gt;\n    &lt;c-child&gt;\n        &lt;template lwc:slot-data=\"item\"&gt;\n            &lt;span&gt;{item.id} - {item.name}&lt;\/span&gt;\n        &lt;\/template&gt;\n    &lt;\/c-child&gt;\n&lt;\/template&gt;\n\n\n&lt;!-- c\/child.html --&gt;\n&lt;template lwc:render-mode=\"light\"&gt; &lt;!-- Child must be light DOM --&gt;\n    &lt;ul&gt;\n        &lt;template for:each={item} for:item=\"item\"&gt;\n            &lt;li key={item.id}&gt;\n                &lt;slot lwc:slot-bind={item}&lt;\/slot&gt;\n            &lt;\/li&gt;\n        &lt;\/template&gt;\n    &lt;\/ul&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u7531\u4e8e\u4f5c\u7528\u57df\u5185\u7684\u69fd\u7247\u6bb5\u4f4d\u4e8e\u7236\u7ec4\u4ef6\u7684\u6a21\u677f\u4e2d\uff0c\u56e0\u6b64\u7236\u7ec4\u4ef6\u62e5\u6709\u69fd\u4f4d\u5185\u5bb9\u3002\u56e0\u6b64\uff0c\u5982\u679c\u7236\u7ec4\u4ef6\u5f15\u7528\u4f5c\u7528\u57df\u6837\u5f0f\u8868\uff0c\u5219\u8fd9\u4e9b\u6837\u5f0f\u4e5f\u9002\u7528\u4e8e\u4f5c\u7528\u57df\u5185\u63d2\u69fd\u7684\u5185\u5bb9\u3002<\/p>\n\n\n\n<p>\u7236\u7ec4\u4ef6\u90e8\u5206\u5448\u73b0\u4f5c\u7528\u57df\u69fd\u7684\u5185\u5bb9\uff0c\u56e0\u6b64\u5fc5\u987b\u5c06\u5176\u5305\u542b\u5728\u6807\u8bb0\u4e2d\u3002\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u4f5c\u7528\u57df\u5185\u7684\u69fd\u5185\u5bb9\u4e3a \u3002\u7236\u7ec4\u4ef6\u521b\u5efa\u6b64\u90e8\u5206\u7247\u6bb5\u3002<code>&lt;template&gt;&lt;\/template&gt;<\/code><code>&lt;span&gt;{item.id} - {item.name}&lt;\/span&gt;<\/code><\/p>\n\n\n\n<p>\u7236\u7ec4\u4ef6\u4e5f\u6e32\u67d3\u6bcf\u4e2a \uff0c\u5b50\u7ec4\u4ef6\u63a7\u5236\u5faa\u73af\u903b\u8f91\u3002 \u4f7f\u7528\u4ece \u4f20\u9012\u7684\u76f8\u540c\u6a21\u677f\u7247\u6bb5\u521b\u5efa\u4efb\u610f\u6570\u91cf\u7684\u63d2\u69fd\u3002<code>item<\/code><code>&lt;c-child&gt;<\/code><code>&lt;c-parent&gt;<\/code><\/p>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u82e5\u8981\u4f7f\u7528\u4f5c\u7528\u57df\u63d2\u69fd\uff0c\u5b50\u7ec4\u4ef6\u5fc5\u987b\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM\u3002 \u4e0d\u652f\u6301\u5f71\u5b50 DOM \u4e2d\u7684\u4f5c\u7528\u57df\u63d2\u69fd\u3002\u7236\u7ea7\u53ef\u4ee5\u662f\u8f7b\u91cf\u7ea7 DOM \u6216\u5f71\u5b50 DOM \u7ec4\u4ef6\u3002<\/p>\n\n\n\n<p>\u6700\u7ec8\u7684 HTML \u5982\u4e0b\u6240\u793a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;c-parent&gt;\n  #shadow-root\n  | &lt;c-child&gt;\n  |  &lt;ul&gt;\n  |    &lt;li&gt;\n  |      &lt;span&gt;1 - One&lt;\/span&gt;\n  |    &lt;\/li&gt;\n  |    &lt;li&gt;\n  |      &lt;span&gt;2 - Two&lt;\/span&gt;\n  |    &lt;\/li&gt;\n  |  &lt;\/ul&gt;\n  | &lt;\/c-child&gt;\n&lt;\/c-parent&gt;<\/code><\/pre>\n\n\n\n<p>\u8981\u5728\u7ec4\u4ef6\u4e2d\u5f15\u5165\u4f5c\u7528\u57df\u69fd\uff0c\u8bf7\u6dfb\u52a0\u6307\u4ee4\u548c .\u6709\u5173\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u69fd\u7684\u6307\u4ee4\u548c\u5d4c\u5957\u6a21\u677f\u7684\u6307\u4ee4\u3002<code>lwc:slot-bindlwc:slot-data<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u591a\u4e2a\u4f5c\u7528\u57df\u63d2\u69fd\u548c\u7ed1\u5b9a<\/h2>\n\n\n\n<p>\u5b50\u7ec4\u4ef6\u53ef\u4ee5\u6709\u591a\u4e2a\u547d\u540d\u7684\u4f5c\u7528\u57df\u63d2\u69fd\uff0c\u4f46\u5b83\u53ea\u80fd\u6709\u4e00\u4e2a\u9ed8\u8ba4\u7684\u4f5c\u7528\u57df\u63d2\u69fd\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n    &lt;c-child&gt;\n        &lt;template lwc:slot-data=\"defaultdata\"&gt; &lt;!-- This is a default slot --&gt;\n            &lt;p&gt;{defaultdata.title}&lt;\/p&gt;\n        &lt;\/template&gt;\n        &lt;template slot=\"slotname1\" lwc:slot-data=\"slot1data\"&gt; &lt;!-- This is a named slot --&gt;\n            &lt;p&gt;{slot1data.title}&lt;\/p&gt;\n        &lt;\/template&gt;\n        &lt;template slot=\"slotname2\" lwc:slot-data=\"slot2data\"&gt; &lt;!-- This is a named slot --&gt;\n            &lt;p&gt;{slot2data.title}&lt;\/p&gt;\n        &lt;\/template&gt;\n    &lt;\/c-child&gt;\n&lt;\/template<\/code><\/pre>\n\n\n\n<p>\u60a8\u53ef\u4ee5\u5c06\u4e0d\u540c\u7684\u4f5c\u7528\u57df\u69fd\u7ed1\u5b9a\u5230\u540c\u4e00\u6570\u636e\u6e90\u3002\u5728\u4e0b\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u9ed8\u8ba4\u7684\u4f5c\u7528\u57df\u5185\u63d2\u69fd\u548c\u4e24\u4e2a\u547d\u540d\u7684\u4f5c\u7528\u57df\u5185\u63d2\u69fd\u5448\u73b0\u6765\u81ea \u7684\u5185\u5bb9\u3002<code>slotdata<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template lwc:render-mode=\"light\"&gt;\n  &lt;!-- This is a default slot --&gt;\n  &lt;slot lwc:slot-bind={slotdata}&gt;&lt;\/slot&gt;\n  &lt;!-- This is a named slot --&gt;\n  &lt;slot name=\"slotname1\" lwc:slot-bind={slotdata}&gt;&lt;\/slot&gt;\n  &lt;!-- This is a named slot --&gt;\n  &lt;slot name=\"slotname2\" lwc:slot-bind={slotdata}&gt;&lt;\/slot&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u53ea\u80fd\u5c06\u4f5c\u7528\u57df\u69fd\u7ed1\u5b9a\u5230\u4e00\u4e2a\u6570\u636e\u6e90\u3002\u4f8b\u5982\uff0c\u5c06\u547d\u540d\u7684\u4f5c\u7528\u57df\u69fd\u7ed1\u5b9a\u5230\u4e24\u7ec4\u4e0d\u540c\u7684\u6570\u636e\uff0c\u5e76\u4e14 \u4f1a\u5bfc\u81f4\u7f16\u8bd1\u5668\u9519\u8bef\u3002<code>namedslotA<\/code><code>slot1data<\/code><code>slot2data<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- Invalid usage of named scoped slot --&gt;\n&lt;template lwc:render-mode=\"light\"&gt;\n  &lt;slot name=\"namedslotA\" lwc:slot-bind={slot1data}&gt;&lt;\/slot&gt;\n  &lt;slot name=\"namedslotA\" lwc:slot-bind={slot2data}&gt;&lt;\/slot&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u5c1d\u8bd5\u5c06\u9ed8\u8ba4\u4f5c\u7528\u57df\u69fd\u7ed1\u5b9a\u5230\u591a\u4e2a\u4e0d\u540c\u7684\u6570\u636e\u96c6\uff0c\u7f16\u8bd1\u5668\u4f1a\u5f15\u53d1\u76f8\u540c\u7684\u9519\u8bef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- Invalid usage of default scoped slot --&gt;\n&lt;template lwc:render-mode=\"light\"&gt;\n  &lt;slot lwc:slot-bind={slot1data}&gt;&lt;\/slot&gt;\n  &lt;slot lwc:slot-bind={slot2data}&gt;&lt;\/slot&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6df7\u5408\u6807\u51c6\u63d2\u69fd\u548c\u5206\u533a\u63d2\u69fd<\/h2>\n\n\n\n<p>\u7531\u4e8e\u7ec4\u4ef6\u4e2d\u53ea\u80fd\u6709\u4e00\u4e2a\u9ed8\u8ba4\u63d2\u69fd\uff0c\u56e0\u6b64\u4e0d\u80fd\u5728\u540c\u4e00\u7ec4\u4ef6\u4e2d\u653e\u7f6e\u6807\u51c6\u9ed8\u8ba4\u63d2\u69fd\u548c\u9ed8\u8ba4\u4f5c\u7528\u57df\u63d2\u69fd\u3002\u4ee5\u4e0b\u4ee3\u7801\u5c06\u5bfc\u81f4\u9519\u8bef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c\/child.html --&gt;\n&lt;!-- Invalid usage of default slots --&gt;\n&lt;template lwc:render-mode=\"light\"&gt;\n  &lt;slot lwc:slot-bind={slotdata}&gt;Default scoped slot&lt;\/slot&gt;\n  &lt;slot&gt;Standard default slot&lt;\/slot&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u5728\u5b50\u7ec4\u4ef6\u4e2d\uff0c\u547d\u540d\u8303\u56f4\u7684\u63d2\u69fd\u548c\u6807\u51c6\u547d\u540d\u63d2\u69fd\u4e0d\u80fd\u5171\u4eab\u76f8\u540c\u7684\u540d\u79f0\u3002\u4ee5\u4e0b\u4ee3\u7801\u5c06\u5bfc\u81f4\u9519\u8bef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c\/child.html --&gt;\n&lt;!-- Invalid usage of named slots --&gt;\n&lt;template lwc:render-mode=\"light\"&gt;\n  &lt;slot name=\"slotname1\" lwc:slot-bind={slotdata}&gt;Named scoped slot&lt;\/slot&gt;\n  &lt;slot name=\"slotname1\"&gt;Standard named slot&lt;\/slot&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u5c06\u7236\u7ec4\u4ef6\u4e2d\u7684\u4f5c\u7528\u57df\u69fd\u7ed1\u5b9a\u5230\u5b50\u7ec4\u4ef6\u4e2d\u7684\u6570\u636e\u65f6\uff0c\u7ec4\u4ef6\u5fc5\u987b\u5305\u542b\u76f8\u540c\u7c7b\u578b\u7684\u69fd\u3002\u4f8b\u5982\uff0c\u5982\u679c\u7236\u7ec4\u4ef6\u5305\u542b\u7ed1\u5b9a\u5230\u5b50\u7ec4\u4ef6\u7684\u4f5c\u7528\u57df\u69fd\uff0c\u5219\u8be5\u5b50\u7ec4\u4ef6\u4e5f\u5fc5\u987b\u5177\u6709\u4f5c\u7528\u57df\u69fd\u3002\u5426\u5219\uff0c\u4e0d\u4f1a\u5448\u73b0\u69fd\u5185\u5bb9\u3002\u5982\u679c\u542f\u7528\u8c03\u8bd5\u6a21\u5f0f\uff0c\u5219\u8fd8\u4f1a\u5728\u5f00\u53d1\u63a7\u5236\u53f0\u4e2d\u8bb0\u5f55\u9519\u8bef\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f5c\u7528\u57df\u63d2\u69fd\u7684\u7075\u6d3b\u6027<\/h2>\n\n\n\n<p>\u60a8\u53ef\u4ee5\u5c06\u4e00\u4e2a\u4f5c\u7528\u57df\u63d2\u69fd\u5d4c\u5957\u5728\u53e6\u4e00\u4e2a\u4f5c\u7528\u57df\u63d2\u69fd\u4e2d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n  &lt;c-table data={data}&gt;\n    &lt;template lwc:slot-data=\"row\"&gt;\n      &lt;c-row row={row}&gt; &lt;!-- This is rendered for every row in the table --&gt;\n        &lt;template lwc:slot-data=\"column\"&gt;\n          &lt;span&gt; &lt;!-- This is rendered for every column in the row --&gt;\n            Coordinates: {row.number} - {column.number} &lt;!-- This can refer to both `row` and `column` --&gt;\n          &lt;\/span&gt;\n        &lt;\/template&gt;\n      &lt;\/c-row&gt;\n    &lt;template&gt;\n  &lt;\/c-table&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>Scoped slots can reference component bindings and scope bindings.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;\n  {title}\n  &lt;c-list&gt;\n    &lt;template lwc:slot-data=\"item\"&gt;\n      &lt;div&gt;{label}&lt;\/div&gt;\n      &lt;!-- label is a component binding that\u2019s repeated in every row of the list --&gt;\n      &lt;span&gt;{item.id} - {item.name}&lt;\/span&gt;\n    &lt;\/template&gt;\n  &lt;\/c-list&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5728 Light DOM \u4e2d\u4f7f\u7528\u4f5c\u7528\u57df\u6837\u5f0f<\/h2>\n\n\n\n<p>\u5728\u8f7b\u91cf\u7ea7 DOM \u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4f5c\u7528\u57df\u6837\u5f0f\u4ec5\u5c06 CSS \u5e94\u7528\u4e8e\u7ec4\u4ef6\u4e0a\u7684\u5143\u7d20\u3002\u6b64\u884c\u4e3a\u7c7b\u4f3c\u4e8e\u4f7f\u7528\u5f71\u5b50 DOM \u8fdb\u884c\u6837\u5f0f\u5c01\u88c5\u3002<\/p>\n\n\n\n<p>\u82e5\u8981\u5411\u7ec4\u4ef6\u6dfb\u52a0\u4f5c\u7528\u57df\u6837\u5f0f\uff0c\u8bf7\u5728\u7ec4\u4ef6\u6587\u4ef6\u5939\u4e2d\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\u3002<code>*.scoped.css<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>myCmp\n    \u251c\u2500\u2500myCmp.html\n    \u251c\u2500\u2500myCmp.css\n    \u2514\u2500\u2500myCmp.scoped.css<\/code><\/pre>\n\n\n\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u5bf9\u4e8e\u9634\u5f71 DOM \u7ec4\u4ef6\u548c\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\uff0c\u60a8\u53ef\u4ee5\u5305\u542b\u4e00\u4e2a\u3001\u4e24\u4e2a\u6216\u4e24\u4e2a CSS \u6587\u4ef6\u3002<\/p>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u5728\u57fa\u4e8e Aura \u7684\u5bb9\u5668\u4e2d\uff0c\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u53ea\u80fd\u52a0\u8f7d\u4f5c\u7528\u57df\u6837\u5f0f\u3002\u4f8b\u5982\uff0c\u5728\u57fa\u4e8e Aura \u7684 Experience Builder \u7ad9\u70b9\u4e2d\uff0c\u60a8\u5fc5\u987b\u5305\u542b\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684\u6587\u4ef6\uff0c\u800c\u4e0d\u662f\u6587\u4ef6\u3002<code>*.scoped.css*.css<\/code><\/p>\n\n\n\n<p>\u8ba9\u6211\u4eec\u68c0\u67e5\u4e00\u4e2a\u5177\u6709\u4f5c\u7528\u57df\u6837\u5f0f\u7684\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- lightCmp.html --&gt;\n&lt;template lwc:render-mode=\"light\"&gt;\n  &lt;p&gt;This is a paragraph in c-light-cmp&lt;\/p&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ lightCmp.js\nimport { LightningElement } from \"lwc\";\n\nexport default class LightCmp extends LightningElement {\n  static renderMode = \"light\";\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* lightCmp.scoped.css *\/\np {\n  background: silver;\n  color: black;\n}<\/code><\/pre>\n\n\n\n<p>\u4f5c\u7528\u57df\u6837\u5f0f\u7684\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;c-light-cmp class=\"c-lightCmp_lightCmp-host\"&gt;\n  &lt;style class=\"c-lightCmp_lightCmp\" type=\"text\/css\"&gt;\n    p.c-lightCmp_lightCmp {\n      background-color: silver;\n      color: black;\n    }\n  &lt;\/style&gt;\n  &lt;p class=\"c-lightCmp_lightCmp\"&gt;This is a paragraph in c-light-cmp&lt;\/p&gt;\n&lt;\/c-light-cmp&gt;<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u6587\u4ef6\u4e0e\u6587\u4ef6\u4e00\u8d77\u4f7f\u7528\uff0c\u5219\u6837\u5f0f\u8868\u5c06\u5728\u6837\u5f0f\u8868\u4e4b\u524d\u6ce8\u5165\u3002\u4f5c\u7528\u57df\u6837\u5f0f CSS \u9009\u62e9\u5668\u4f18\u5148\u4e8e\u65e0\u4f5c\u7528\u57df\u9009\u62e9\u5668\uff0c\u56e0\u4e3a\u5b83\u4eec\u662f\u6700\u540e\u58f0\u660e\u7684\u3002<code>*.css<\/code><code>*.scoped.css<\/code><code>*.css<\/code><code>*.scoped.css<\/code><\/p>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u5982\u679c\u5728\u6a21\u677f\u4e0a\u4f7f\u7528\u4f5c\u7528\u57df\u6837\u5f0f\u8868\u548c\u65e0\u4f5c\u7528\u57df\u6837\u5f0f\u8868\uff0c\u5219\u540c\u65f6\u5e94\u7528\u8fd9\u4e24\u79cd\u6837\u5f0f\u8868\u3002\u6ce8\u5165\u987a\u5e8f\u4f1a\u5f71\u54cd\u6d4f\u89c8\u5668\u5728\u91cd\u590d\u9009\u62e9\u5668\u65f6\u5e94\u7528\u54ea\u4e9b\u6837\u5f0f\u3002\u89c1\u6811\u63a5\u8fd1\u65e0\u77e5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* lightCmp.css *\/\np {\n  background: yellow;\n  color: #777;\n}<\/code><\/pre>\n\n\n\n<p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528\u4f5c\u7528\u57df\u6837\u5f0f\uff0c\u4f46\u65e0\u4f5c\u7528\u57df\u6837\u5f0f\u8868\u4e2d\u7684\u6837\u5f0f\u53ef\u80fd\u4f1a\u4ece\u7ec4\u4ef6\u4e2d\u6e17\u51fa\u3002<code>c-light-cmp<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c-app --&gt;\n&lt;template&gt;\n  &lt;!-- This paragraph is styled yellow from lightCmp.css --&gt;\n  &lt;p&gt;This is a paragraph in c-app shadow DOM&lt;\/p&gt;\n  &lt;c-light-cmp&gt;&lt;\/c-light-cmp&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u5728\u524d\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6bb5\u843d\u7ee7\u627f\u81ea \u7684\u6837\u5f0f\u3002\u8981\u8986\u76d6 \u4e2d\u7684\u6837\u5f0f\uff0c\u8bf7\u5305\u542b\u4f5c\u7528\u57df\u6837\u5f0f\u8868\u3002<code>c-app<\/code><code>lightCmp.css<\/code><code>lightCmp.css<\/code><code>app.scoped.css<\/code><\/p>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u6211\u4eec\u4e0d\u5efa\u8bae\u4f7f\u7528\u8be5\u89c4\u5219\uff0c\u56e0\u4e3a\u5b83\u4f1a\u4f7f\u8c03\u8bd5\u66f4\u52a0\u56f0\u96be\u3002\u5f53\u60a8\u5728\u4f5c\u7528\u57df\u5185\u6837\u5f0f\u8868\u548c\u65e0\u4f5c\u7528\u57df\u6837\u5f0f\u8868\u4e2d\u4f7f\u7528\u6837\u5f0f\u58f0\u660e\u65f6\uff0c\u4f5c\u7528\u57df\u6837\u5f0f\u5177\u6709\u66f4\u5927\u7684\u7279\u5f02\u6027\uff0c\u5e76\u4e14\u5176\u6837\u5f0f\u5c06\u5e94\u7528\u4e8e\u7ec4\u4ef6\u3002<code>!important<\/code><code>!important<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f5c\u7528\u57df\u533a\u57df<\/h2>\n\n\n\n<p>\u4f7f\u7528 \u65f6\uff0cCSS \u9009\u62e9\u5668\u7684\u8303\u56f4\u9650\u5b9a\u4e3a\u7ec4\u4ef6 HTML \u6587\u4ef6\u4e2d\u7684\u6240\u6709\u5143\u7d20\u3002<code>*.scoped.css<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c-my-cmp --&gt;\n&lt;template&gt;\n  &lt;div&gt;\n    &lt;span&gt;&lt;\/span&gt;\n    &lt;button class=\"my-button\"&gt;&lt;\/button&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u5728\u4e0b\u9762\u7684 CSS \u4e2d\uff0c\u6240\u6709\u9009\u62e9\u5668\u90fd\u4e0e\u6a21\u677f\u4e2d\u7684\u5143\u7d20\u5339\u914d\uff0c\u5e76\u4e14\u53ea\u5339\u914d\u8fd9\u4e9b\u5143\u7d20\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* myCmp.css *\/\ndiv {\n}\nspan {\n}\nbutton {\n}\ndiv &gt; span {\n}\ndiv button {\n}\n.my-button {\n}<\/code><\/pre>\n\n\n\n<p>\u6839\u5143\u7d20\u53ef\u4ee5\u4f7f\u7528 \u4f5c\u4e3a\u76ee\u6807\uff0c\u5373\u4f7f\u5728\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u4e2d\u4e5f\u662f\u5982\u6b64\u3002<code>c-light-cmp<\/code><code>:host<\/code><\/p>\n\n\n\n<p>CSS \u8303\u56f4\u4f7f\u7528\u81ea\u5b9a\u4e49 CSS \u7c7b\u6765\u9632\u6b62\u6837\u5f0f\u4ece\u7ec4\u4ef6\u4e2d\u6cc4\u6f0f\u51fa\u6765\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4ee5\u6839\u5143\u7d20\u4e3a\u76ee\u6807<\/h2>\n\n\n\n<p>\u7531\u4e8e\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4e0d\u9650\u5b9a\u8f7b\u91cf\u7ea7 DOM \u6837\u5f0f\u7684\u8303\u56f4\uff0c\u56e0\u6b64\u4f2a\u9009\u62e9\u5668\u5f15\u7528\u6700\u63a5\u8fd1\u7684\u5f71\u5b50\u6839\u5bbf\u4e3b\u5143\u7d20\uff08\u5982\u679c\u6709\uff09\u3002\u5bf9\u4e8e\u8f7b\u91cf\u7ea7 DOM \u8303\u56f4\u6837\u5f0f\uff0c\u9009\u62e9\u5668\u5f15\u7528\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u7684\u6839\u5143\u7d20\uff0c\u5373\u4f5c\u7528\u57df DOM \u533a\u57df\u7684\u6839\u3002<code>:host<\/code><code>:host<\/code><\/p>\n\n\n\n<p>\u5047\u8bbe\u60a8\u5728\u4e00\u4e2a\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u4e0a\u6709\u4e00\u4e2a\u65e0\u4f5c\u7528\u57df\u548c\u4f5c\u7528\u57df\u7684\u6837\u5f0f\u8868\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* light.css *\/\n:host {\n  background: red;\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* light.scoped.css *\/\n:host {\n  background: blue;\n}<\/code><\/pre>\n\n\n\n<p>\u8be5\u7ec4\u4ef6\u5448\u73b0\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;c-shadow&gt;\n  &lt;!-- red background --&gt;\n  #shadow-root\n  &lt;c-light class=\"c-light_light-host\"&gt;\n    &lt;!-- blue background --&gt;\n    &lt;style&gt;\n      :host {\n        background: red;\n      }\n      :c-light_light-host {\n        background: blue;\n      }\n    &lt;\/style&gt;\n  &lt;\/c-light&gt;\n&lt;\/c-shadow&gt;<\/code><\/pre>\n\n\n\n<p>\u5728\u524d\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u4e3a\u4f5c\u7528\u57df\u6837\u5f0f\u8fdb\u884c\u8f6c\u6362\u3002<code>:host<\/code><\/p>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u4e0d\u652f\u6301\u9009\u62e9\u5668\u3002<code>:host-context()<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5c06\u4f5c\u7528\u57df\u6837\u5f0f\u4e0e\u5408\u6210\u5f71\u5b50 DOM \u8fdb\u884c\u6bd4\u8f83<\/h2>\n\n\n\n<p>Light DOM \u8303\u56f4\u6837\u5f0f\u4e0e LWC \u7684\u5408\u6210\u9634\u5f71\u8303\u56f4\u6837\u5f0f\u6709\u4e00\u4e9b\u4e0d\u540c\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8f7b\u91cf\u7ea7 DOM \u8303\u56f4\u6837\u5f0f\u4f7f\u7528\u7c7b\u6765\u786e\u5b9a\u8303\u56f4\uff0c\u4f46\u5408\u6210\u9634\u5f71 DOM \u4f7f\u7528 HTML \u5c5e\u6027\u3002<\/li>\n\n\n\n<li>\u8f7b\u91cf\u7ea7 DOM \u4f5c\u7528\u57df\u6837\u5f0f\u5728\u4f5c\u7528\u57df\u6837\u5f0f\u8868\u4e2d\u4e0d\u53d7\u652f\u6301\u3002<code>@import<\/code><\/li>\n\n\n\n<li>\u8f7b\u91cf\u7ea7 DOM \u8303\u56f4\u6837\u5f0f\u4e0d\u9002\u7528\u4e8e\u5728\u00a0<code>lwc\uff1adom=\u201cmanual\u201d<\/code>\u00a0\u4e2d\u624b\u52a8\u6ce8\u5165\u6a21\u677f\u7684\u5185\u5bb9\uff0c\u4f8b\u5982\uff0c\u4f7f\u7528 \u6216 \u6ce8\u5165\u7684\u5185\u5bb9\u3002<code>Element.appendChildElement.innerHTML<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"build-components-in-mixed-shadow-mode-(developer-preview)\">\u5728\u6df7\u5408\u9634\u5f71\u6a21\u5f0f\u4e0b\u6784\u5efa\u7ec4\u4ef6\uff08\u5f00\u53d1\u4eba\u5458\u9884\u89c8\u7248\uff09<\/h2>\n\n\n\n<p>\u6df7\u5408\u9634\u5f71\u6a21\u5f0f\u4f7f\u7ec4\u4ef6\u80fd\u591f\u4f7f\u7528\u672c\u673a\u9634\u5f71 DOM\uff0c\u5373\u4f7f\u5e94\u7528\u4e86\u5408\u6210\u9634\u5f71 polyfill\u3002<\/p>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u6df7\u5408\u9634\u5f71\u6a21\u5f0f\u4f5c\u4e3a\u5f00\u53d1\u4eba\u5458\u9884\u89c8\u7248\u63d0\u4f9b\u3002\u9664\u975e Salesforce \u5728\u6587\u6863\u3001\u65b0\u95fb\u7a3f\u6216\u516c\u5f00\u58f0\u660e\u4e2d\u5ba3\u5e03\u5176\u6b63\u5f0f\u53d1\u5e03\uff0c\u5426\u5219\u6b64\u529f\u80fd\u4e0d\u4f1a\u6b63\u5f0f\u53d1\u5e03\u3002\u6240\u6709\u547d\u4ee4\u3001\u53c2\u6570\u548c\u5176\u4ed6\u529f\u80fd\u90fd\u53ef\u80fd\u968f\u65f6\u66f4\u6539\u6216\u5f03\u7528\uff0c\u6055\u4e0d\u53e6\u884c\u901a\u77e5\u3002\u4e0d\u8981\u5b9e\u73b0\u4f7f\u7528\u8fd9\u4e9b\u547d\u4ee4\u6216\u5de5\u5177\u5f00\u53d1\u7684\u529f\u80fd\u3002<\/p>\n\n\n\n<p>\u73b0\u5728\u6240\u6709\u4e3b\u6d41\u6d4f\u89c8\u5668\u90fd\u652f\u6301\u5f71\u5b50 DOM\u3002Salesforce \u7ef4\u62a4\u65e7\u7248\u6d4f\u89c8\u5668\uff08\u5982\u65e7\u7248\u672c\u7684 Microsoft Edge\uff09\u7684\u5408\u6210\u5f71\u5b50 polyfill\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u7b80\u5316\u5f00\u53d1\u548c\u6d4b\u8bd5\uff0c\u76ee\u524d\u751a\u81f3\u5728\u652f\u6301\u5f71\u5b50 DOM \u7684\u6d4f\u89c8\u5668\u4e0a\u4f7f\u7528 polyfill\u3002\u4f7f\u7528\u6df7\u5408\u9634\u5f71\u6a21\u5f0f\uff0c\u60a8\u53ef\u4ee5\u83b7\u5f97\u5728\u5e94\u7528\u4e2d\u5c3d\u53ef\u80fd\u591a\u5730\u4f7f\u7528\u539f\u751f\u9634\u5f71\u7684\u901f\u5ea6\u548c\u6548\u7387\u3002\u800c\u4e14\uff0c\u5c06\u6765\u53ef\u4ee5\u66f4\u8f7b\u677e\u5730\u8fc1\u79fb\u4ee5\u5b8c\u5168\u4f7f\u7528\u672c\u673a\u5f71\u5b50\u3002<\/p>\n\n\n\n<p>\u539f\u751f\u9634\u5f71\u548c\u5408\u6210\u9634\u5f71\u6709\u51e0\u4e2a\u533a\u522b\uff0c\u4f8b\u5982\u5b83\u4eec\u5982\u4f55\u901a\u8fc7\u63d2\u69fd\u4e0e\u6837\u5f0f\u5b9e\u73b0\u5c01\u88c5\u3002\u867d\u7136\u5e94\u7528\u4f9d\u8d56\u4e8e\u5168\u5c40\u6837\u5f0f\u8868\u6765\u5e94\u7528\u5408\u6210\u5f71\u5b50 DOM \u4e2d\u7684\u6837\u5f0f\uff0c\u4f46\u7ec4\u4ef6\u7684\u6837\u5f0f\u4f1a\u6dfb\u52a0\u5230\u539f\u751f\u5f71\u5b50\u4e2d\u7684\u7ec4\u4ef6\u5305\u4e2d\u3002\u6b64\u5916\uff0c\u5408\u6210\u9634\u5f71\u4e0d\u652f\u6301\u67d0\u4e9b\u5f71\u5b50 DOM \u529f\u80fd\uff0c\u4f8b\u5982 \u3002\u6700\u91cd\u8981\u7684\u662f\uff0c\u539f\u751f\u9634\u5f71\u7ec4\u4ef6\u6bd4\u5408\u6210\u9634\u5f71\u7ec4\u4ef6\u66f4\u5feb\u3001\u6027\u80fd\u66f4\u9ad8\u3002<code>::part<\/code><\/p>\n\n\n\n<p>\u4e0b\u9762\u662f\u5177\u6709\u6df7\u5408\u6a21\u5f0f\u7ec4\u4ef6\u7684\u5e94\u7528\u793a\u4f8b\u3002\u5b83\u6709\u4e00\u4e2a\u7236\u7ec4\u4ef6\u548c\u5b50\u7ec4\u4ef6\u3002\u5f53\u60a8\u5728 Web \u63a7\u5236\u53f0\u4e2d\u68c0\u67e5\u672c\u673a\u5f71\u5b50\u7ec4\u4ef6\u65f6\uff0c\u5b83\u4eec\u4f1a\u663e\u793a\u5728\u6807\u7b7e\u4e2d\u3002\u5408\u6210\u9634\u5f71\u6839\u5728\u5f00\u53d1\u4eba\u5458\u5de5\u5177\u4e2d\u4e0d\u53ef\u89c1\uff0c\u4f46\u4ee5\u4e0b\u793a\u4f8b\u4e2d\u663e\u793a\u4e86\u5b83\u4eec\uff0c\u4ee5\u4fbf\u8fdb\u884c\u8bf4\u660e\u3002<code>c-app<\/code><code>c-native<\/code><code>c-synthetic<\/code><code>#shadow-root<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c-app --&gt;\n&lt;c-app&gt;\n    &lt;c-native&gt;\n     #shadow-root\n     |  &lt;div&gt;Your content for the native component&lt;\/div&gt;\n    &lt;\/c-native&gt;\n    &lt;c-synthetic&gt;\n        &lt;div&gt;Your content for the synthetic component&lt;\/div&gt;\n    &lt;\/c-synthetic&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u7236\u7ec4\u4ef6\u548c\u5b50\u7ec4\u4ef6\u4e5f\u79f0\u4e3a\u7956\u5148\u7ec4\u4ef6\u548c\u540e\u4ee3\u7ec4\u4ef6\u3002\u76f8\u53cd\uff0c\u6269\u5c55\u53e6\u4e00\u4e2a\u7ec4\u4ef6\u7684\u7ec4\u4ef6\u79f0\u4e3a\u5b50\u7c7b\u53ca\u5176\u8d85\u7c7b\u3002<\/p>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>LWC \u5141\u8bb8\u9057\u4f20\uff0c\u4f46\u4e0d\u5efa\u8bae\u8fd9\u6837\u505a\uff0c\u56e0\u4e3a\u7ec4\u5408\u901a\u5e38\u66f4\u6709\u6548\u3002\u7ee7\u627f\u4e0d\u80fd\u8de8\u547d\u540d\u7a7a\u95f4\u5de5\u4f5c\uff0c\u5e76\u4e14\u65e0\u6cd5\u6269\u5c55\u547d\u540d\u7a7a\u95f4\u3002<code>lightning<\/code><\/p>\n\n\n\n<p>\u5408\u6210\u7ec4\u4ef6\u53ef\u4ee5\u5305\u542b\u672c\u673a\u7ec4\u4ef6\uff0c\u4f46\u4e0d\u652f\u6301\u53cd\u4e4b\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c-app --&gt;\n&lt;c-app&gt;\n  #shadow-root (synthetic)\n  &lt;c-synthetic&gt;\n    #shadow-root (synthetic)\n    &lt;c-native&gt;\n      #shadow-root (native)\n      &lt;p&gt;Content inside a native shadow root&lt;\/p&gt;\n    &lt;\/c-native&gt;\n  &lt;\/c-synthetic&gt;\n&lt;\/c-app&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u542f\u7528\u6df7\u5408\u9634\u5f71\u6a21\u5f0f<\/h2>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6df7\u5408\u5f71\u5b50\u6a21\u5f0f\u5728\u60a8\u7684\u7ec4\u7ec7\u4e2d\u4e0d\u53ef\u7528\u3002\u8054\u7cfb Salesforce \u4ee5\u53c2\u4e0e\u5f00\u53d1\u4eba\u5458\u9884\u89c8\u7248\u3002<\/p>\n\n\n\n<p>\u8981\u5728\u7ec4\u4ef6\u4e0a\u542f\u7528\u6df7\u5408\u9634\u5f71\u6a21\u5f0f\uff0c\u8bf7\u5c06 static \u5c5e\u6027\u8bbe\u7f6e\u4e3a \u3002<code>shadowSupportMode<\/code><code>any<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ native.js\nimport { LightningElement } from \"lwc\";\nexport default class MixedModeApp extends LightningElement {\n  static shadowSupportMode = \"any\";\n}<\/code><\/pre>\n\n\n\n<p>\u7684\u6709\u6548\u503c\u5305\u62ec\uff1a<code>shadowSupportMode<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>any<\/code>&#8211; \u5c3d\u53ef\u80fd\u5728\u672c\u673a\u9634\u5f71 DOM \u4e2d\u6e32\u67d3\u6574\u4e2a\u7ec4\u4ef6\u5b50\u6811\u3002\u5982\u679c\u6d4f\u89c8\u5668\u4e0d\u652f\u6301\u5f71\u5b50 DOM\uff0c\u5219\u5b50\u6811\u5c06\u4ee5\u5408\u6210\u5f71\u5b50\u5f62\u5f0f\u5448\u73b0\u3002<\/li>\n\n\n\n<li><code>reset<\/code>&#8211; \u4f7f\u5b50\u7c7b\u80fd\u591f\u9009\u62e9\u4e0d\u63a5\u6536\u6765\u81ea\u5176\u8d85\u7c7b\u7684\u503c\u3002 \u4ec5\u5f53\u7ec4\u4ef6\u7684\u8d85\u7c7b\u6b63\u5728\u4f7f\u7528\u4e14\u6ca1\u6709\u7236\u7ec4\u4ef6\u6b63\u5728\u4f7f\u7528 \u65f6\u624d\u9002\u7528\u3002<code>shadowSupportMode<\/code><code>reset<\/code><code>any<\/code><code>any<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u5728\u8bbe\u7f6e\u4e3a\u542f\u7528\u6df7\u5408\u5f71\u5b50\u6a21\u5f0f\u4e4b\u524d\uff0c\u6211\u4eec\u5efa\u8bae\u68c0\u67e5\u5b50\u6811\u4e2d\u7684\u6240\u6709\u7ec4\u4ef6\u662f\u5426\u90fd\u4e0e\u672c\u673a\u5f71\u5b50 DOM \u517c\u5bb9\u3002\u4f8b\u5982\uff0c\u4e0d\u80fd\u5728\u672c\u673a\u5f71\u5b50 DOM \u5b50\u6811\u4e2d\u4f7f\u7528\u5c5e\u6027\u9009\u62e9\u5668\uff0c\u56e0\u4e3a\u8be5\u9009\u62e9\u5668\u4ec5\u5728\u5408\u6210\u5f71\u5b50 DOM \u4e2d\u8d77\u4f5c\u7528\u3002\u76f8\u53cd\uff0c\u8bf7\u67e5\u770b\u60a8\u7684\u6d4f\u89c8\u5668\u662f\u5426\u652f\u6301\u672c\u673a\u5f71\u5b50 DOM \u4e2d\u7684\u4f2a\u7c7b\u3002 \u6216\u8005\uff0c\u60a8\u53ef\u4ee5\u4ece\u53f6\u7ec4\u4ef6\u5f00\u59cb\uff0c\u7136\u540e\u6cbf\u7740\u7ec4\u4ef6\u6811\u5411\u4e0a\u79fb\u52a8\uff0c\u4ee5\u786e\u4fdd\u6df7\u5408\u9634\u5f71\u6a21\u5f0f\u6309\u9884\u671f\u5de5\u4f5c\u3002<code>shadowSupportMode<\/code><code>any<\/code><code>[dir=\"\"]<\/code><code>:dir()<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u7528\u6df7\u5408\u9634\u5f71\u6a21\u5f0f<\/h2>\n\n\n\n<p>\u5982\u679c\u7236\u7ec4\u4ef6\u4f7f\u7528 \uff0c\u5219\u5b50\u6811\u4e2d\u7684\u6240\u6709\u7ec4\u4ef6\u90fd\u5728\u672c\u673a\u9634\u5f71\u4e2d\u8fd0\u884c\uff0c\u800c\u4e0d\u7ba1\u5176\u503c\u5982\u4f55\u3002\u672c\u673a\u5f71\u5b50\u6a21\u5f0f\u7ec4\u4ef6\u53ea\u80fd\u5305\u542b\u672c\u673a\u5f71\u5b50\u6a21\u5f0f\u5b50\u7ec4\u4ef6\u3002\u6b64\u9650\u5236\u662f\u5c06\u5c5e\u6027\u5e94\u7528\u4e8e\u6574\u4e2a\u5b50\u6811\u7684\u526f\u4f5c\u7528\u3002<code>any<\/code><code>shadowSupportMode<\/code><code>shadowSupportMode<\/code><\/p>\n\n\n\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u63d2\u69fd\u5185\u5bb9\u4ee5\u672c\u673a\u9634\u5f71\u5448\u73b0\u3002\u5f00\u69fd\u5185\u5bb9\u4e0d\u662f\u4ece\u5176\u5d4c\u5957\u7684\u7ec4\u4ef6\u6d3e\u751f\u7684\uff0c\u56e0\u6b64\u60a8\u53ef\u4ee5\u5c06\u5408\u6210\u9634\u5f71\u5185\u5bb9\u63d2\u5165\u5230\u672c\u673a\u9634\u5f71\u7ec4\u4ef6\u4e2d\u3002\u8fd9\u4e5f\u610f\u5473\u7740\uff0c\u63d2\u69fd\u5185\u5bb9\u4e0d\u53d7\u6d4f\u89c8\u5668\u5448\u73b0\u5305\u542b\u63d2\u69fd\u7684\u7ec4\u4ef6\u7684\u65b9\u5f0f\u7684\u5f71\u54cd\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u7684\u6d4f\u89c8\u5668\u5728\u5408\u6210\u9634\u5f71\u4e2d\u6e32\u67d3\u672c\u673a\u7ec4\u4ef6\uff0c\u5219\u63d2\u5165\u8be5\u7ec4\u4ef6\u7684\u672c\u673a\u5185\u5bb9\u4ecd\u4f1a\u5728\u672c\u673a\u9634\u5f71\u4e2d\u6e32\u67d3\u3002<code>#shadow-root<\/code><\/p>\n\n\n\n<p>\u4e0b\u9762\uff0c\u6709\u4e00\u4e2a\u5e26\u6709\u5b50\u7ec4\u4ef6\u7684\u539f\u751f\u5f71\u5b50\u5b50\u6811\uff0c\u4ee5\u53ca\u5f00\u69fd\u7684\u5185\u5bb9\u3002 \u5728\u539f\u751f\u5f71\u5b50\u4e2d\u8fd0\u884c\uff0c\u56e0\u4e3a\u5b83\u662f \u7684\u540e\u4ee3\uff0c\u4f46\u53ef\u4ee5\u5728\u5408\u6210\u5f71\u5b50\u4e2d\uff0c\u56e0\u4e3a\u5b83\u4e0d\u662f \u7684\u540e\u4ee3\u3002<code>&lt;c-parent&gt;<\/code><code>&lt;c-child&gt;<\/code><code>&lt;c-slotted&gt;<\/code><code>&lt;c-child&gt;<\/code><code>&lt;c-parent&gt;<\/code><code>&lt;c-slotted&gt;<\/code><code>&lt;c-parent&gt;<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c-app --&gt;\n&lt;c-app&gt;\n  #shadow-root (synthetic)\n  &lt;c-parent&gt;\n    #shadow-root (native)\n    &lt;p&gt;Parent component&lt;\/p&gt;\n    &lt;slot&gt;\n      &lt;c-slotted&gt;\n        #shadow-root (synthetic)\n        &lt;p&gt;Slotted content&lt;\/p&gt;\n    &lt;\/slot&gt;\n    &lt;c-child&gt;\n      #shadow-root (native)\n      &lt;p&gt;Child component&lt;\/p&gt;\n    &lt;\/c-child&gt;\n  &lt;\/c-parent&gt;\n&lt;\/c-app&gt;<\/code><\/pre>\n\n\n\n<p>\u5728\u652f\u6301\u5f71\u5b50 DOM \u7684\u6d4f\u89c8\u5668\u4e0a\uff0c\u4ee5\u4e0b\u662f\u5f53\u60a8\u5305\u542b polyfill \u5e76\u8bbe\u7f6e\u4e3a or \u65f6\u7236\u7ec4\u4ef6\u548c\u5b50\u7ec4\u4ef6\u7684\u5448\u73b0\u65b9\u5f0f\u3002<code>@lwc\/synthetic-shadow<\/code><code>shadowSupportMode<\/code><code>any<\/code><code>reset<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c-parent --&gt;\n&lt;template&gt;\n  &lt;c-child&gt;&lt;\/c-child&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u7236\u6bcd<\/th><th>\u5b69\u5b50<\/th><th>\u9634\u5f71\u6a21\u5f0f<\/th><\/tr><\/thead><tbody><tr><td>&#8211;<\/td><td>&#8211;<\/td><td>\u5408\u6210<\/td><\/tr><tr><td>\u91cd\u7f6e<\/td><td>\u91cd\u7f6e<\/td><td>\u5408\u6210<\/td><\/tr><tr><td>\u4efb\u4f55<\/td><td>\u4efb\u4f55<\/td><td>\u672c\u5730<\/td><\/tr><tr><td>\u4efb\u4f55<\/td><td>\u91cd\u7f6e<\/td><td>\u672c\u5730<\/td><\/tr><tr><td>\u91cd\u7f6e<\/td><td>\u4efb\u4f55<\/td><td>\u7236\u7ea7\uff1a\u5408\u6210\uff0c\u5b50\u7ea7\uff1a\u539f\u751f<\/td><\/tr><tr><td>&#8211;<\/td><td>\u4efb\u4f55<\/td><td>\u7236\u7ea7\uff1a\u5408\u6210\uff0c\u5b50\u7ea7\uff1a\u539f\u751f<\/td><\/tr><tr><td>&#8211;<\/td><td>\u91cd\u7f6e<\/td><td>\u5408\u6210<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5305\u542b polyfill \u65f6\uff0c\u901a\u8fc7\u5c06 \u8bbe\u7f6e\u4e3a \u5c06\u9634\u5f71\u6a21\u5f0f\u91cd\u7f6e\u4e3a\u9ed8\u8ba4\u884c\u4e3a\u3002<code>@lwc\/synthetic-shadow<\/code><code>shadowSupportMode<\/code><code>reset<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u5b58\u5728 polyfill\uff0c\u5219\u5c06\u9634\u5f71\u6a21\u5f0f\u8bbe\u7f6e\u4e3a\u5408\u6210\u9634\u5f71\u3002<code>reset<\/code><\/li>\n\n\n\n<li>\u5982\u679c polyfill \u4e0d\u5b58\u5728\uff0c\u5219\u4e0d\u4f1a\u4ea7\u751f\u4efb\u4f55\u5f71\u54cd\uff0c\u5e76\u4e14\u7ec4\u4ef6\u4f1a\u5728\u672c\u673a\u9634\u5f71\u4e2d\u5448\u73b0\u3002<code>shadowSupportMode<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u8981\u786e\u5b9a\u5143\u7d20\u662f\u5426\u5177\u6709\u5408\u6210\u5f71\u5b50\u6839\uff0c\u8bf7\u4f7f\u7528 .<code>this.template.synthetic<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export default class extends LightningElement {\n  renderedCallback() {\n    console.log(\"Synthetic?\", !!this.template.synthetic);\n  }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u4f7f\u7528\u539f\u751f\u548c\u5408\u6210\u9634\u5f71\u7ec4\u4ef6<\/h2>\n\n\n\n<p>\u5e94\u7528\u53ef\u4ee5\u5305\u542b\u672c\u673a\u548c\u5408\u6210\u9634\u5f71\u7ec4\u4ef6\u3002\u6b64\u793a\u4f8b\u5047\u5b9a\u5e94\u7528\u6b63\u5728\u4f7f\u7528 polyfill\u3002<code>@lwc\/synthetic-shadow<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c-app --&gt;\n&lt;c-app&gt;\n  &lt;c-native&gt;\n    #shadow-root \n    |  &lt;div&gt;Your content for the native component&lt;\/div&gt;\n  &lt;\/c-native&gt;\n  &lt;c-synthetic&gt;\n    &lt;div&gt;Your content for the synthetic component&lt;\/div&gt;\n  &lt;\/c-synthetic&gt;\n&lt;\/c-app&gt;<\/code><\/pre>\n\n\n\n<p>\u8be5\u5e94\u7528\u7a0b\u5e8f\u5305\u62ec\u4e24\u4e2a\u4ee5\u4e0d\u540c\u6a21\u5f0f\u8fd0\u884c\u7684\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c-app --&gt;\n&lt;template&gt;\n  &lt;c-native&gt;&lt;\/c-native&gt;\n  &lt;c-synthetic&gt;&lt;\/c-synthetic&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u8fd9\u662f\u672c\u673a\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c-native --&gt;\n&lt;template&gt;\n  &lt;div&gt;Your content for the native component&lt;\/div&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ native.js\nimport { LightningElement } from \"lwc\";\nexport default class Native extends LightningElement {\n  static shadowSupportMode = \"any\";\n}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u662f\u5408\u6210\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c-synthetic --&gt;\n&lt;template&gt;\n  &lt;div&gt;Your content for the synthetic component&lt;\/div&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ synthetic.js\nimport { LightningElement } from \"lwc\";\nexport default class Synthetic extends LightningElement {}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u539f\u751f\u9634\u5f71\u4e0e\u5408\u6210\u9634\u5f71\u7684\u6bd4\u8f83<\/h2>\n\n\n\n<p>\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u8ba8\u8bba\u539f\u751f\u9634\u5f71\u548c\u5408\u6210\u9634\u5f71\u4e4b\u95f4\u7684\u4e00\u4e9b\u533a\u522b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5143\u7d20\u548c\u63d2\u69fd<\/h3>\n\n\n\n<p>\u5728\u539f\u751f\u9634\u5f71 DOM \u4e2d\uff0c\u5143\u7d20\u5728\u7ec4\u4ef6\u7684\u8f7b\u91cf\u7ea7 DOM \u4e2d\u5448\u73b0\uff0c\u5e76\u5206\u914d\u7ed9\u5b50\u7ec4\u4ef6\u7684\u9634\u5f71 DOM \u4e2d\u7684\u63d2\u69fd\u3002\u4f46\u5728\u5408\u6210\u9634\u5f71 DOM \u4e2d\uff0cLWC \u4e0d\u4f1a\u6e32\u67d3\u4f20\u9012\u7ed9\u5b50\u7ec4\u4ef6\u7684\u5143\u7d20\uff0c\u9664\u975e\u5b83\u4eec\u88ab\u5206\u914d\u7ed9\u63d2\u69fd\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u5305\u542b \u7684\u7ec4\u4ef6\uff0c\u5176\u8de8\u5ea6\u672a\u5206\u914d\u7ed9\u69fd\u3002\u5728\u539f\u751f\u9634\u5f71\u4e2d\uff0c\u6b64\u8de8\u5ea6\u5728 DOM \u4e2d\u5448\u73b0\u3002\u4f46\u662f\uff0c\u5728\u5408\u6210\u9634\u5f71\u4e2d\uff0cDOM \u4e2d\u4e0d\u5b58\u5728\u8de8\u5ea6\u3002<code>c-parent<\/code><code>c-child<\/code><code>c-child<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c-parent --&gt;\n&lt;template&gt;\n  &lt;c-child&gt;\n    &lt;span&gt;This is some text in a span tag&lt;\/span&gt;\n  &lt;\/c-child&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c-child --&gt;\n&lt;template&gt;\n  &lt;p&gt;child&lt;\/p&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u82e5\u8981\u786e\u5b9a\u5143\u7d20\u5206\u914d\u5230\u54ea\u4e2a\u69fd\uff0c\u8bf7\u8c03\u7528 API\u3002\u4ee5\u524d\uff0c\u5f53\u52a0\u8f7d\u5408\u6210\u9634\u5f71 polyfill \u65f6\uff0c\u5206\u914d\u7ed9\u672c\u673a\u9634\u5f71\u7ec4\u4ef6\u4e2d\u63d2\u69fd\u7684\u5143\u7d20\u4f1a\u8fd4\u56de\u00a0<code>assignedSlot<\/code>\u3002\u73b0\u5728\uff0cAPI \u8fd4\u56de\u672c\u673a\u9634\u5f71\u7ec4\u4ef6\u4e2d\u5f00\u69fd\u5143\u7d20\u7684\u5143\u7d20\u3002<code>assignedSlotnull&lt;slot><\/code><\/p>\n\n\n\n<p>\u82e5\u8981\u8fd4\u56de\u6307\u5b9a\u5750\u6807\u5904\u6240\u6709\u5143\u7d20\u7684\u6570\u7ec4\uff0c\u8bf7\u4f7f\u7528\u00a0<code>elementsFromPoint<\/code>\u00a0API\uff0c\u5305\u62ec\u7528\u4e8e DOM \u4e2d\u4e0d\u53ef\u89c1\u7684\u5408\u6210\u9634\u5f71 DOM \u5143\u7d20\u3002\u5728\u4ee5\u4e0b\u793a\u4f8b\u4e2d\uff0c\u662f\u4e0d\u53ef\u89c1\u7684\uff08\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u4e3a\u96f6\uff09\uff0c\u4f46\u5b83\u5305\u542b\u7684 \u662f\u53ef\u89c1\u7684\u3002<code>&lt;c-inner>&lt;div><\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;c-outer&gt;\n  #shadow-root\n  &lt;c-inner&gt;\n    #shadow-root\n    &lt;div&gt;&lt;\/div&gt;\n  &lt;\/c-inner&gt;\n&lt;\/c-outer&gt;<\/code><\/pre>\n\n\n\n<p>\u5728\u5408\u6210\u5f71\u5b50\u4e2d\uff0c\u8c03\u7528\u8fd4\u56de \u3002\u5728\u539f\u751f\u9634\u5f71\u4e2d\uff0c\u5b83\u8fd4\u56de<code>outer.shadowRoot.elementsFromPoint()<\/code><code>[&lt;div&gt;, &lt;c-outer&gt;, &lt;html&gt;]<\/code><code>[&lt;c-inner&gt;, &lt;c-outer&gt;, &lt;html&gt;]<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u9020\u578b<\/h3>\n\n\n\n<p>\u4f7f\u7528\u5408\u6210\u9634\u5f71\uff0c\u5e94\u7528\u7a0b\u5e8f\u4f9d\u9760\u5168\u5c40\u6837\u5f0f\u8868\u5728\u6574\u4e2a DOM \u4e2d\u5e94\u7528\u6837\u5f0f\u3002\u5728\u539f\u751f\u9634\u5f71\u4e2d\uff0c\u8fd9\u662f\u4e0d\u53ef\u80fd\u7684\uff0c\u56e0\u4e3a\u5728\u539f\u751f\u9634\u5f71\u4e2d\uff0c\u7ec4\u4ef6\u7684\u6837\u5f0f\u5fc5\u987b\u6dfb\u52a0\u5230\u7ec4\u4ef6\u5305\u4e2d\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\uff0c\u4f7f\u7528\u5408\u6210\u9634\u5f71\u65f6\uff0c\u6587\u6863\u9876\u5c42\u7684\u5171\u4eab\u6837\u5f0f\u8868\u53ef\u4ee5\u8bbe\u7f6e\u9875\u9762\u4e0a\u6240\u6709\u7ec4\u4ef6\u7684\u6837\u5f0f\u3002\u82e5\u8981\u9632\u6b62\u5c06\u9876\u5c42\u6837\u5f0f\u5e94\u7528\u4e8e\u5b50\u7ec4\u4ef6\uff0c\u8bf7\u4f7f\u7528\u00a0<code>@import<\/code>\u00a0\u5c06\u5171\u4eab\u6837\u5f0f\u8868\u5305\u542b\u5728\u9700\u8981\u5171\u4eab\u6837\u5f0f\u8868\u7684\u7ec4\u4ef6\u4e2d\u3002<\/p>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u5728\u591a\u4e2a\u7ec4\u4ef6\u4e2d\u5bfc\u5165\u76f8\u540c\u7684\u6837\u5f0f\u8868\u4e0d\u4f1a\u5f71\u54cd\u6027\u80fd\uff0c\u56e0\u4e3a LWC \u4f1a\u4e3a\u60a8\u5904\u7406 CSS \u7684\u91cd\u590d\u6570\u636e\u5220\u9664\u3002<\/p>\n\n\n\n<p>\u867d\u7136 CSS \u6a21\u5757\u5bfc\u5165\u9002\u7528\u4e8e\u5927\u591a\u6570\u5171\u4eab\u7684 CSS \u5e93\uff0c\u4f46\u5982\u679c CSS \u5305\u542b\u904d\u5386\u9634\u5f71\u8fb9\u754c\u7684\u9009\u62e9\u5668\uff0c\u5219\u5b83\u4e0d\u8d77\u4f5c\u7528\u3002\u5047\u8bbe\u4f60\u6709\u4e00\u4e2a\u5e26\u6709\u8fd9\u4e2a CSS \u7684\u7236\u7ec4\u4ef6\u548c\u5b50\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.parent .child {\n  color: red;\n}<\/code><\/pre>\n\n\n\n<p>\u5982\u679c \u548c \u9009\u62e9\u5668\u4f4d\u4e8e\u5355\u72ec\u7684\u7ec4\u4ef6\u4e2d\uff0c\u5219\u6b64 CSS \u4e0d\u8d77\u4f5c\u7528\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u8bf7\u4f7f\u7528\u00a0CSS \u81ea\u5b9a\u4e49\u5c5e\u6027\u6216\u5176\u4ed6\u6280\u672f\u6839\u636e\u5b50\u9879\u7684\u7236\u7ea7\u6709\u6761\u4ef6\u5730\u5448\u73b0\u5b50\u9879\u3002<code>.parent.child<\/code><\/p>\n\n\n\n<p>\u4f8b\u5982\u3002\u60a8\u53ef\u4ee5\u5c06\u8be5\u5c5e\u6027\u4f20\u9012\u7ed9\u5b50\u7ec4\u4ef6\u3002<code>color<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Parent extends LightningElement {\n  myColor = \"red\";\n}\n\nclass Child extends LightningElement {\n  @api color;\n  get myStyle() {\n    return `color: ${this.color}`;\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u5b50\u7ec4\u4ef6\u4e2d\u663e\u793a\u7684\u989c\u8272\u7531\u7236\u7ec4\u4ef6\u786e\u5b9a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- c-parent --&gt;\n&lt;template&gt;\n  &lt;c-child color={myColor}&gt;&lt;\/c-child&gt;\n&lt;\/template&gt;\n\n&lt;!-- c-child --&gt;\n&lt;template&gt;\n  &lt;h1 style={myStyle}&gt;My color is determined by my parent&lt;\/h1&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u6216\u8005\uff0c\u5982\u679c\u4e0d\u9700\u8981\u5bf9\u7ec4\u4ef6\u8fdb\u884c\u5c01\u88c5\uff0c\u8bf7\u8003\u8651\u8fc1\u79fb\u7ec4\u4ef6\u4ee5\u6539\u7528\u8f7b\u91cf\u7ea7 DOM\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u53ef\u53ca\u6027<\/h3>\n\n\n\n<p>\u4f7f\u7528\u5408\u6210\u9634\u5f71\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u5728\u7236\u7ec4\u4ef6\u548c\u5b50\u7ec4\u4ef6\u4e2d\u52a8\u6001\u8bbe\u7f6e\u5c5e\u6027\u6765\u521b\u5efa\u8de8\u9634\u5f71\u8fb9\u754c\u7684\u5f15\u7528\u3002\u4f7f\u7528\u539f\u751f\u9634\u5f71\u65f6\uff0c\u60a8\u4e0d\u80fd\u6267\u884c\u76f8\u540c\u7684\u64cd\u4f5c\uff0c\u56e0\u4e3a\u5143\u7d20 ID \u7684\u8303\u56f4\u9650\u5b9a\u4e3a\u7279\u5b9a\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u63a8\u8350\u4ee5\u4e0b\u9009\u9879\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u4e00\u4e2a\u5143\u7d20\u5f15\u7528\u4e86\u53e6\u4e00\u4e2a\u5143\u7d20\u7684 ID\uff0c\u8bf7\u5c06\u4e24\u8005\u653e\u5728\u540c\u4e00\u4e2a\u7ec4\u4ef6\u4e2d\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u4f7f\u7528 \uff0c\u5219\u4f7f\u7528 \u5728\u5143\u7d20\u4e4b\u95f4\u590d\u5236\u5b57\u7b26\u4e32\u3002<code>aria-labelledby<\/code><code>aria-label<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u6216\u8005\uff0c\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f\u4e0d\u9700\u8981\u5c01\u88c5\u7684\u7ec4\u4ef6\uff0c\u8bf7\u8003\u8651\u4f7f\u7528\u8f7b\u91cf\u7ea7 DOM\u3002\u4f8b\u5982\uff0c\u5728\u540c\u4e00\u4e2a\u5f71\u5b50 DOM \u7236\u7ec4\u4ef6\u4e2d\uff0c\u6709\u4e24\u4e2a\u8f7b\u91cf\u7ea7 DOM \u7ec4\u4ef6\u4f5c\u4e3a\u540c\u7ea7\u7ec4\u4ef6\uff0c\u5e76\u4e14 ID \u5728\u540c\u7ea7\u7ec4\u4ef6\u4e4b\u95f4\u5171\u4eab\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u751f\u547d\u5468\u671f\u94a9\u5b50<\/h3>\n\n\n\n<p>\u4f7f\u7528\u5408\u6210\u9634\u5f71\u65f6\uff0c\u5982\u679c\u4ec5\u5c06\u69fd\u5143\u7d20\u5206\u914d\u7ed9\u69fd\uff0c\u5219\u4f1a\u6e32\u67d3\u8fd9\u4e9b\u5143\u7d20\u3002\u5bf9\u4e8e\u4ece\u672a\u5206\u914d\u7ed9\u69fd\u7684\u69fd\u5143\u7d20\uff0c\u4ece\u4e0d\u8c03\u7528\u5176\u751f\u547d\u5468\u671f\u6302\u94a9\u3002<\/p>\n\n\n\n<p>\u6b64\u5916\uff0c\u5408\u6210\u9634\u5f71\u4e2d\u7684\u751f\u547d\u5468\u671f\u94a9\u5b50\u5728\u5206\u914d\u540e\u6309\u51fa\u73b0\u987a\u5e8f\u8c03\u7528\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u5728\u539f\u751f\u9634\u5f71\u4e2d\uff0c\u5b83\u4eec\u6309\u6a21\u677f\u4e2d\u7684\u51fa\u73b0\u987a\u5e8f\u8c03\u7528\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u975e\u7ec4\u5408\u4e8b\u4ef6<\/h3>\n\n\n\n<p>\u4f7f\u7528\u5408\u6210\u5f71\u5b50\uff0c\u5982\u679c\u4e8b\u4ef6\u6e90\u81ea\u5b50\u6811\u4e2d\u7684\u975e LWC \u7ec4\u4ef6\uff0c\u4fa6\u542c\u5668\u53ef\u4ee5\u5904\u7406\u6839 LWC \u8282\u70b9\u4e4b\u5916\u7684\u975e\u7ec4\u5408\u4e8b\u4ef6\u3002\u4f46\u662f\uff0c\u5f71\u5b50 DOM \u4e0d\u652f\u6301\u6b64\u884c\u4e3a\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u57fa\u672c Lightning \u7ec4\u4ef6<\/h3>\n\n\n\n<p>\u6df7\u5408\u9634\u5f71\u6a21\u5f0f\u76ee\u524d\u4e0d\u652f\u6301\u57fa\u672c\u7ec4\u4ef6\u3002Salesforce \u6b63\u5728\u6309\u7167 Web \u7ec4\u4ef6\u6807\u51c6\u4e3a\u672c\u673a\u5f71\u5b50 DOM \u51c6\u5907\u57fa\u672c\u7ec4\u4ef6\u3002\u968f\u7740\u6211\u4eec\u52aa\u529b\u5b9e\u73b0\u672a\u6765\u5bf9\u6df7\u5408\u5f71\u5b50\u6a21\u5f0f\u548c\u539f\u751f\u5f71\u5b50 DOM \u7684\u652f\u6301\uff0c\u57fa\u672c\u7ec4\u4ef6\u7684\u5185\u90e8\u7ed3\u6784\u4f1a\u4e0d\u65ad\u53d8\u5316\u3002 \u76ee\u524d\uff0c\u5f53\u57fa\u672c\u7ec4\u4ef6\u653e\u7f6e\u5728\u672c\u673a\u9634\u5f71\u7ec4\u4ef6\u4e2d\u65f6\uff0c\u53ef\u80fd\u65e0\u6cd5\u663e\u793a\u6b63\u786e\u7684\u6837\u5f0f;\u539f\u751f\u9634\u5f71\u6e32\u67d3\u6240\u6709\u5b50\u7ec4\u4ef6\uff0c\u800c\u4e0d\u6e32\u67d3\u5408\u6210\u9634\u5f71\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879<\/h3>\n\n\n\n<p>\u6211\u4eec\u7684\u57fa\u51c6\u6d4b\u8bd5\u8868\u660e\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u539f\u751f\u9634\u5f71\u7ec4\u4ef6\u6bd4\u5408\u6210\u7ec4\u4ef6\u5feb 50%\u3002\u5220\u9664\u5408\u6210\u9634\u5f71 polyfill \u4e5f\u4f1a\u5c06 LWC \u7684\u6574\u4f53 JavaScript \u5927\u5c0f\u51cf\u5c11\u4e00\u534a\u3002\u6df7\u5408\u9634\u5f71\u6a21\u5f0f\u4f7f\u6211\u4eec\u66f4\u63a5\u8fd1\u4e8e\u80fd\u591f\u5b8c\u5168\u8fc1\u79fb\u5230\u539f\u751f\u9634\u5f71\uff0c\u7136\u540e\u4f7f\u6211\u4eec\u80fd\u591f\u4ece LWC \u4e2d\u5b8c\u5168\u5220\u9664 polyfill\u3002<\/p>\n\n\n\n<p>\u5408\u6210\u9634\u5f71\u4e0d\u652f\u6301\u67d0\u4e9b\u5f71\u5b50 DOM \u529f\u80fd\uff0c\u4f8b\u5982 .<code>::part<\/code><\/p>\n\n\n\n<p>\u8bf7\u8003\u8651\u539f\u751f\u9634\u5f71\u548c\u5408\u6210\u9634\u5f71\u4e4b\u95f4\u7684\u8fd9\u4e9b\u989d\u5916\u5dee\u5f02\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u5408\u6210\u9634\u5f71<\/th><th>\u539f\u751f\u9634\u5f71<\/th><\/tr><\/thead><tbody><tr><td>\u63d2\u69fd\u662f\u6309\u7167\u76ee\u6807\u53ef\u63d2\u69fd\u7ec4\u4ef6\u4e2d\u5b9a\u4e49\u7684\u987a\u5e8f\u521b\u5efa\u7684\u3002<\/td><td>\u63d2\u69fd\u662f\u6309\u7167\u8c03\u7528\u63d2\u69fd\u7684\u7ec4\u4ef6\u4e2d\u5b9a\u4e49\u7684\u987a\u5e8f\u521b\u5efa\u7684\u3002<\/td><\/tr><tr><td>\u8be5\u5c5e\u6027\u4e0d\u4f1a\u9690\u85cf\u9634\u5f71\u5185\u5bb9\u3002<code>innerText<\/code><\/td><td>\u8be5\u5c5e\u6027\u9690\u85cf\u9634\u5f71\u5185\u5bb9\u3002<code>innerText<\/code><\/td><\/tr><tr><td><code>this.template.firstChild<\/code>\u8fd4\u56de\u6a21\u677f\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u3002<\/td><td><code>this.template.firstChild<\/code>\u5728\u67d0\u4e9b\u6d4f\u89c8\u5668\u4e2d\u8fd4\u56de\u672c\u673a\u9634\u5f71\u4e2d\u7684\u5143\u7d20\u3002<code>&lt;style&gt;<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u6863\u5bf9\u8c61\u6a21\u578b \uff08DOM\uff09 \u8868\u793a HTML \u9875\u9762\uff0c\u4ee5\u4fbf\u60a8\u53ef\u4ee5\u4f7f\u7528 JavaScript \u6216\u6807\u51c6 DOM API \u5904\u7406\u5176\u5185\u5bb9\u3001\u7ed3\u6784\u548c\u6837\u5f0f\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6 DOM API \u8bbf\u95ee\u7ec4\u4ef6\u4e2d\u7684\u5143\u7d20\uff0c\u65e0\u8bba\u662f\u5426\u4f7f\u7528\u6a21\u677f\u5f15\u7528\u9009\u62e9\u5668\u3002\u867d\u7136\u6211\u4eec\u4e0d\u5efa\u8bae\u64cd\u4f5c DOM\uff0c\u4f46\u67d0\u4e9b\u7b2c\u4e09\u65b9 JavaScript \u5e93\u9700\u8981\u63a5\u7ba1 DOM\u3002querySelector()<\/p>\n","protected":false},"author":1,"featured_media":3827,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[233],"tags":[241],"class_list":["post-3826","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-lightning-web-","tag--dom"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4f7f\u7528 DOM - \u767d\u767d\u968f\u7b14<\/title>\n<meta name=\"description\" content=\"\u6587\u6863\u5bf9\u8c61\u6a21\u578b \uff08DOM\uff09 \u8868\u793a HTML \u9875\u9762\uff0c\u4ee5\u4fbf\u60a8\u53ef\u4ee5\u4f7f\u7528 JavaScript \u6216\u6807\u51c6 DOM API \u5904\u7406\u5176\u5185\u5bb9\u3001\u7ed3\u6784\u548c\u6837\u5f0f\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6 DOM API \u8bbf\u95ee\u7ec4\u4ef6\u4e2d\u7684\u5143\u7d20\uff0c\u65e0\u8bba\u662f\u5426\u4f7f\u7528\u6a21\u677f\u5f15\u7528\u9009\u62e9\u5668\u3002\u867d\u7136\u6211\u4eec\u4e0d\u5efa\u8bae\u64cd\u4f5c DOM\uff0c\u4f46\u67d0\u4e9b\u7b2c\u4e09\u65b9 JavaScript \u5e93\u9700\u8981\u63a5\u7ba1 DOM\u3002querySelector()\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.ponybai.com\/?p=3826\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f7f\u7528 DOM - \u767d\u767d\u968f\u7b14\" \/>\n<meta property=\"og:description\" content=\"\u6587\u6863\u5bf9\u8c61\u6a21\u578b \uff08DOM\uff09 \u8868\u793a HTML \u9875\u9762\uff0c\u4ee5\u4fbf\u60a8\u53ef\u4ee5\u4f7f\u7528 JavaScript \u6216\u6807\u51c6 DOM API \u5904\u7406\u5176\u5185\u5bb9\u3001\u7ed3\u6784\u548c\u6837\u5f0f\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6 DOM API \u8bbf\u95ee\u7ec4\u4ef6\u4e2d\u7684\u5143\u7d20\uff0c\u65e0\u8bba\u662f\u5426\u4f7f\u7528\u6a21\u677f\u5f15\u7528\u9009\u62e9\u5668\u3002\u867d\u7136\u6211\u4eec\u4e0d\u5efa\u8bae\u64cd\u4f5c DOM\uff0c\u4f46\u67d0\u4e9b\u7b2c\u4e09\u65b9 JavaScript \u5e93\u9700\u8981\u63a5\u7ba1 DOM\u3002querySelector()\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.ponybai.com\/?p=3826\" \/>\n<meta property=\"og:site_name\" content=\"\u767d\u767d\u968f\u7b14\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-08T03:32:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-02T03:33:00+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/dom.png\" \/>\n\t<meta property=\"og:image:width\" content=\"420\" \/>\n\t<meta property=\"og:image:height\" content=\"157\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"ponybai\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"ponybai\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/www.ponybai.com\/?p=3826#article\",\"isPartOf\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=3826\"},\"author\":{\"name\":\"ponybai\",\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\"},\"headline\":\"\u4f7f\u7528 DOM\",\"datePublished\":\"2024-01-08T03:32:35+00:00\",\"dateModified\":\"2023-12-02T03:33:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=3826\"},\"wordCount\":541,\"publisher\":{\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\"},\"keywords\":[\"\u4f7f\u7528 DOM\"],\"articleSection\":[\"Lightning Web \u7ec4\u4ef6\u5f00\u53d1\u4eba\u5458\u6307\u5357\"],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.ponybai.com\/?p=3826\",\"url\":\"http:\/\/www.ponybai.com\/?p=3826\",\"name\":\"\u4f7f\u7528 DOM - \u767d\u767d\u968f\u7b14\",\"isPartOf\":{\"@id\":\"http:\/\/www.ponybai.com\/#website\"},\"datePublished\":\"2024-01-08T03:32:35+00:00\",\"dateModified\":\"2023-12-02T03:33:00+00:00\",\"description\":\"\u6587\u6863\u5bf9\u8c61\u6a21\u578b \uff08DOM\uff09 \u8868\u793a HTML \u9875\u9762\uff0c\u4ee5\u4fbf\u60a8\u53ef\u4ee5\u4f7f\u7528 JavaScript \u6216\u6807\u51c6 DOM API \u5904\u7406\u5176\u5185\u5bb9\u3001\u7ed3\u6784\u548c\u6837\u5f0f\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6 DOM API \u8bbf\u95ee\u7ec4\u4ef6\u4e2d\u7684\u5143\u7d20\uff0c\u65e0\u8bba\u662f\u5426\u4f7f\u7528\u6a21\u677f\u5f15\u7528\u9009\u62e9\u5668\u3002\u867d\u7136\u6211\u4eec\u4e0d\u5efa\u8bae\u64cd\u4f5c DOM\uff0c\u4f46\u67d0\u4e9b\u7b2c\u4e09\u65b9 JavaScript \u5e93\u9700\u8981\u63a5\u7ba1 DOM\u3002querySelector()\",\"breadcrumb\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=3826#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.ponybai.com\/?p=3826\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.ponybai.com\/?p=3826#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"http:\/\/www.ponybai.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f7f\u7528 DOM\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.ponybai.com\/#website\",\"url\":\"http:\/\/www.ponybai.com\/\",\"name\":\"\u767d\u767d\u968f\u7b14\",\"description\":\"Salesforce\u5b98\u65b9\u8bb2\u5e08\",\"publisher\":{\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.ponybai.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\",\"name\":\"ponybai\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2025\/03\/cropped-Ihsans-WeChatQR.jpg\",\"contentUrl\":\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2025\/03\/cropped-Ihsans-WeChatQR.jpg\",\"width\":248,\"height\":248,\"caption\":\"ponybai\"},\"logo\":{\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/121.37.188.161\"],\"url\":\"http:\/\/www.ponybai.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u4f7f\u7528 DOM - \u767d\u767d\u968f\u7b14","description":"\u6587\u6863\u5bf9\u8c61\u6a21\u578b \uff08DOM\uff09 \u8868\u793a HTML \u9875\u9762\uff0c\u4ee5\u4fbf\u60a8\u53ef\u4ee5\u4f7f\u7528 JavaScript \u6216\u6807\u51c6 DOM API \u5904\u7406\u5176\u5185\u5bb9\u3001\u7ed3\u6784\u548c\u6837\u5f0f\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6 DOM API \u8bbf\u95ee\u7ec4\u4ef6\u4e2d\u7684\u5143\u7d20\uff0c\u65e0\u8bba\u662f\u5426\u4f7f\u7528\u6a21\u677f\u5f15\u7528\u9009\u62e9\u5668\u3002\u867d\u7136\u6211\u4eec\u4e0d\u5efa\u8bae\u64cd\u4f5c DOM\uff0c\u4f46\u67d0\u4e9b\u7b2c\u4e09\u65b9 JavaScript \u5e93\u9700\u8981\u63a5\u7ba1 DOM\u3002querySelector()","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":"http:\/\/www.ponybai.com\/?p=3826","og_locale":"zh_CN","og_type":"article","og_title":"\u4f7f\u7528 DOM - \u767d\u767d\u968f\u7b14","og_description":"\u6587\u6863\u5bf9\u8c61\u6a21\u578b \uff08DOM\uff09 \u8868\u793a HTML \u9875\u9762\uff0c\u4ee5\u4fbf\u60a8\u53ef\u4ee5\u4f7f\u7528 JavaScript \u6216\u6807\u51c6 DOM API \u5904\u7406\u5176\u5185\u5bb9\u3001\u7ed3\u6784\u548c\u6837\u5f0f\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6 DOM API \u8bbf\u95ee\u7ec4\u4ef6\u4e2d\u7684\u5143\u7d20\uff0c\u65e0\u8bba\u662f\u5426\u4f7f\u7528\u6a21\u677f\u5f15\u7528\u9009\u62e9\u5668\u3002\u867d\u7136\u6211\u4eec\u4e0d\u5efa\u8bae\u64cd\u4f5c DOM\uff0c\u4f46\u67d0\u4e9b\u7b2c\u4e09\u65b9 JavaScript \u5e93\u9700\u8981\u63a5\u7ba1 DOM\u3002querySelector()","og_url":"http:\/\/www.ponybai.com\/?p=3826","og_site_name":"\u767d\u767d\u968f\u7b14","article_published_time":"2024-01-08T03:32:35+00:00","article_modified_time":"2023-12-02T03:33:00+00:00","og_image":[{"width":420,"height":157,"url":"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/dom.png","type":"image\/png"}],"author":"ponybai","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"ponybai","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/www.ponybai.com\/?p=3826#article","isPartOf":{"@id":"http:\/\/www.ponybai.com\/?p=3826"},"author":{"name":"ponybai","@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883"},"headline":"\u4f7f\u7528 DOM","datePublished":"2024-01-08T03:32:35+00:00","dateModified":"2023-12-02T03:33:00+00:00","mainEntityOfPage":{"@id":"http:\/\/www.ponybai.com\/?p=3826"},"wordCount":541,"publisher":{"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883"},"keywords":["\u4f7f\u7528 DOM"],"articleSection":["Lightning Web \u7ec4\u4ef6\u5f00\u53d1\u4eba\u5458\u6307\u5357"],"inLanguage":"zh-Hans"},{"@type":"WebPage","@id":"http:\/\/www.ponybai.com\/?p=3826","url":"http:\/\/www.ponybai.com\/?p=3826","name":"\u4f7f\u7528 DOM - \u767d\u767d\u968f\u7b14","isPartOf":{"@id":"http:\/\/www.ponybai.com\/#website"},"datePublished":"2024-01-08T03:32:35+00:00","dateModified":"2023-12-02T03:33:00+00:00","description":"\u6587\u6863\u5bf9\u8c61\u6a21\u578b \uff08DOM\uff09 \u8868\u793a HTML \u9875\u9762\uff0c\u4ee5\u4fbf\u60a8\u53ef\u4ee5\u4f7f\u7528 JavaScript \u6216\u6807\u51c6 DOM API \u5904\u7406\u5176\u5185\u5bb9\u3001\u7ed3\u6784\u548c\u6837\u5f0f\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6 DOM API \u8bbf\u95ee\u7ec4\u4ef6\u4e2d\u7684\u5143\u7d20\uff0c\u65e0\u8bba\u662f\u5426\u4f7f\u7528\u6a21\u677f\u5f15\u7528\u9009\u62e9\u5668\u3002\u867d\u7136\u6211\u4eec\u4e0d\u5efa\u8bae\u64cd\u4f5c DOM\uff0c\u4f46\u67d0\u4e9b\u7b2c\u4e09\u65b9 JavaScript \u5e93\u9700\u8981\u63a5\u7ba1 DOM\u3002querySelector()","breadcrumb":{"@id":"http:\/\/www.ponybai.com\/?p=3826#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.ponybai.com\/?p=3826"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.ponybai.com\/?p=3826#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"http:\/\/www.ponybai.com\/"},{"@type":"ListItem","position":2,"name":"\u4f7f\u7528 DOM"}]},{"@type":"WebSite","@id":"http:\/\/www.ponybai.com\/#website","url":"http:\/\/www.ponybai.com\/","name":"\u767d\u767d\u968f\u7b14","description":"Salesforce\u5b98\u65b9\u8bb2\u5e08","publisher":{"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.ponybai.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883","name":"ponybai","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/image\/","url":"http:\/\/www.ponybai.com\/wp-content\/uploads\/2025\/03\/cropped-Ihsans-WeChatQR.jpg","contentUrl":"http:\/\/www.ponybai.com\/wp-content\/uploads\/2025\/03\/cropped-Ihsans-WeChatQR.jpg","width":248,"height":248,"caption":"ponybai"},"logo":{"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/121.37.188.161"],"url":"http:\/\/www.ponybai.com\/?author=1"}]}},"_links":{"self":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts\/3826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3826"}],"version-history":[{"count":2,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts\/3826\/revisions"}],"predecessor-version":[{"id":3830,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts\/3826\/revisions\/3830"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/media\/3827"}],"wp:attachment":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3826"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}