Skip to content

Commit 8edb5e3

Browse files
ikxinKiritaniAyakaJustineo
authored
docs: translate custom-elements.md (#1013)
Co-authored-by: 时瑶 <[email protected]> Co-authored-by: GU Yiling <[email protected]>
1 parent c10b999 commit 8edb5e3

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

src/api/custom-elements.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
<!-- TODO: translation -->
2-
# Custom Elements API {#custom-elements-api}
1+
# 自定义元素 API {#custom-elements-api}
32

43
## defineCustomElement() {#definecustomelement}
54

6-
This method accepts the same argument as [`defineComponent`](#definecomponent), but instead returns a native [Custom Element](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements) class constructor.
5+
此方法接受的参数与 [`defineComponent`](#definecomponent) 相同,但返回一个原生[自定义元素](https://developer.mozilla.org/zh-CN/docs/Web/Web_Components/Using_custom_elements)类构造函数。
76

8-
- **Type**
7+
- **类型**
98

109
```ts
1110
function defineCustomElement(
@@ -20,28 +19,28 @@ This method accepts the same argument as [`defineComponent`](#definecomponent),
2019
interface CustomElementsOptions {
2120
styles?: string[]
2221

23-
// the following options are 3.5+
22+
// 以下选项在 3.5+ 版本中支持
2423
configureApp?: (app: App) => void
2524
shadowRoot?: boolean
2625
nonce?: string
2726
}
2827
```
2928

30-
> Type is simplified for readability.
29+
> 类型为简化版,便于阅读。
3130
32-
- **Details**
31+
- **详情**
3332

34-
In addition to normal component options, `defineCustomElement()` also supports a number of options that are custom-elements-specific:
33+
除了常规的组件选项,`defineCustomElement()` 还支持一系列特定于自定义元素的选项:
3534

36-
- **`styles`**: an array of inlined CSS strings for providing CSS that should be injected into the element's shadow root.
35+
- **`styles`**:一个内联 CSS 字符串数组,用于提供应注入元素 shadow root 的 CSS。
3736

38-
- **`configureApp`** <sup class="vt-badge" data-text="3.5+"/>: a function that can be used to configure the Vue app instance for the custom element.
37+
- **`configureApp`** <sup class="vt-badge" data-text="3.5+"/>:一个函数,可用于配置自定义元素的 Vue 应用实例。
3938

40-
- **`shadowRoot`** <sup class="vt-badge" data-text="3.5+"/>: `boolean`, defaults to `true`. Set to `false` to render the custom element without a shadow root. This means `<style>` in custom element SFCs will no longer be encapsulated.
39+
- **`shadowRoot`** <sup class="vt-badge" data-text="3.5+"/>`boolean`,默认为 `true`。设置为 `false` 以在不带 shadow root 的情况下渲染自定义元素。这意味着自定义元素单文件组件中的 `<style>` 将不再被封装隔离。
4140

42-
- **`nonce`** <sup class="vt-badge" data-text="3.5+"/>: `string`, if provided, will be set as the `nonce` attribute on style tags injected to the shadow root.
41+
- **`nonce`** <sup class="vt-badge" data-text="3.5+"/>`string`,如果提供,将在注入到 shadow root 样式标签上设置 `nonce` attribute
4342

44-
Note that instead of being passed as part of the component itself, these options can also be passed via a second argument:
43+
注意,这些选项也可以不作为组件本身的一部分传递,而是通过第二个参数传递:
4544

4645
```js
4746
import Element from './MyElement.ce.vue'
@@ -53,35 +52,35 @@ This method accepts the same argument as [`defineComponent`](#definecomponent),
5352
})
5453
```
5554

56-
The return value is a custom element constructor that can be registered using [`customElements.define()`](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define).
55+
返回值是一个自定义元素构造函数,可以使用 [`customElements.define()`](https://developer.mozilla.org/zh-CN/docs/Web/API/CustomElementRegistry/define) 注册。
5756

58-
- **Example**
57+
- **示例**
5958

6059
```js
6160
import { defineCustomElement } from 'vue'
6261

6362
const MyVueElement = defineCustomElement({
64-
/* component options */
63+
/* 组件选项 */
6564
})
6665

67-
// Register the custom element.
66+
// 注册自定义元素
6867
customElements.define('my-vue-element', MyVueElement)
6968
```
7069

71-
- **See also**
70+
- **参考**
7271

73-
- [Guide - Building Custom Elements with Vue](/guide/extras/web-components#building-custom-elements-with-vue)
72+
- [指南 - 使用 Vue 构建自定义元素](/guide/extras/web-components#building-custom-elements-with-vue)
7473

75-
- Also note that `defineCustomElement()` requires [special config](/guide/extras/web-components#sfc-as-custom-element) when used with Single-File Components.
74+
- 请注意,使用单文件组件时,`defineCustomElement()` 需要进行[特殊配置](/guide/extras/web-components#sfc-as-custom-element)
7675

7776
## useHost() <sup class="vt-badge" data-text="3.5+"/> {#usehost}
7877

79-
A Composition API helper that returns the host element of the current Vue custom element.
78+
一个组合式 API 辅助函数,返回当前 Vue 自定义元素的宿主元素。
8079

8180
## useShadowRoot() <sup class="vt-badge" data-text="3.5+"/> {#useshadowroot}
8281

83-
A Composition API helper that returns the shadow root of the current Vue custom element.
82+
一个组合式 API 辅助函数,返回当前 Vue 自定义元素的 shadow root
8483

8584
## this.$host <sup class="vt-badge" data-text="3.5+"/> {#this-host}
8685

87-
An Options API property that exposes the host element of the current Vue custom element.
86+
一个选项式 API property,暴露当前 Vue 自定义元素的宿主元素。

0 commit comments

Comments
 (0)