Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update web-components.md #1063

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

GBD1024
Copy link

@GBD1024 GBD1024 commented Feb 11, 2025

在创建 pull request 之前

请确认:

  • 我已经阅读过项目的 wiki 了解相关注意事项。
  • 我对翻译内容的改动不包含基于英文原版的扩展、删减或演绎 (如有,请移步至英文文档仓库讨论,相关结论会被定期从英文版同步)

问题描述

翻译了web-components.md

Copy link

vercel bot commented Feb 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-zh-cn ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 12, 2025 0:03am

@@ -301,102 +301,92 @@ declare module 'vue' {
```

## 非 Vue Web Components 和 TypeScript {#non-vue-web-components-and-typescript}
<!-- TODO: translation -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请尽量保持译文与原文每段占用的行数一致,有助于以后的更新同步不易错乱,见翻译须知

此处 TODO 应为空行,其他位置的改动同理

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哦哦好,谢谢提醒,祝你元宵节快乐 ^_^

Copy link
Contributor

@KiritaniAyaka KiritaniAyaka Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可能是我的表达有误,不是指通过添加空行来保持行号一致,不过刚刚发现上游已经调整了格式,可以直接参照上游最新的格式保持段落行号,抱歉🙏

稍后我会 review 并且提出修改建议

Copy link
Contributor

@KiritaniAyaka KiritaniAyaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同步了 vuejs/docs#3114 这个 PR 的格式更改

Comment on lines +296 to 297
// 请务必在此处输入 Vue 组件类型(SomeComponent,*而不是* SomeElement)
// 自定义元素的名称中需要连字符,因此请在此处使用连字符元素名称。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 请务必在此处输入 Vue 组件类型(SomeComponent,*而不是* SomeElement)。
// 自定义元素的名称中需要连字符,因此请在此处使用连字符元素名称。
// 请务必在此处输入 Vue 组件类型
// (SomeComponent,*而不是* SomeElement)。
// 自定义元素的名称中需要连字符,
// 因此请在此处使用连字符元素名称。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样修改了后面的行号不就不对应了嘛

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样修改了后面的行号不就不对应了嘛

因为刚刚发现上游修复了格式问题,PR 链接放在上面了,这里参照的是最新格式,你可以对照上游的最新内容看看是否有问题:https://github.com/vuejs/docs/blob/main/src/guide/extras/web-components.md?plain=1

Comment on lines +305 to +306

以下是在非Vue构建的自定义元素的SFC模板中启用类型检查的推荐方法。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
以下是在非Vue构建的自定义元素的SFC模板中启用类型检查的推荐方法。
以下是在非 Vue 构建的自定义元素的 SFC 模板中启用类型检查的推荐方法。

Comment on lines +312 to +313

假设我们有一个自定义元素,其中定义了一些 JS 属性和事件,并且它被包含在一个名为 `some-lib`的库中:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
假设我们有一个自定义元素,其中定义了一些 JS 属性和事件,并且它被包含在一个名为 `some-lib`的库中:
假设我们有一个自定义元素,其中定义了一些 JS 属性和事件,并且它发布在名为 `some-lib` 的库中:

Comment on lines +351 to 355
实现细节已经省略,但重要的是我们有两个东西的类型定义:属性类型和事件类型。


让我们创建一个类型助手,以便在 Vue 中轻松注册自定义元素类型定义:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
实现细节已经省略,但重要的是我们有两个东西的类型定义:属性类型和事件类型。
让我们创建一个类型助手,以便在 Vue 中轻松注册自定义元素类型定义:
实现细节已省略,重点是我们为两个东西提供了类型定义:prop 类型和事件类型。
让我们创建一个类型工具,以便在 Vue 中轻松注册自定义元素类型定义:

// Vue 特别从 `$props` 类型读取属性定义
// 请注意,我们将元素的属性与全局 HTML 属性和 Vue 的特殊属性结合在一起

/** @deprecated 不要在自定义元素引用上使用 $props 属性,这仅用于模板属性类型检查 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @deprecated 不要在自定义元素引用上使用 $props 属性,这仅用于模板属性类型检查 */
/** @deprecated 不要在自定义元素引用上使用 $props 属性,
这仅用于模板属性类型检查 */

// 使用 $emit 专门定义事件类型
// Vue 特别从 `$emit` 类型读取事件类型
// 请注意,`$emit` 期望我们将 `Events` 映射到特定格式
/** @deprecated 不要在自定义元素引用上使用 $emit 属性,这仅用于模板属性类型检查 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @deprecated 不要在自定义元素引用上使用 $emit 属性,这仅用于模板属性类型检查 */
/** @deprecated 不要在自定义元素引用上使用 $emit 属性,
这仅用于模板属性类型检查 */

Comment on lines +424 to +425
假设 some-lib 将其源 TypeScript 文件构建到 dist/ 文件夹中。some-lib 的用户可以像这样导入 SomeElement 并在 Vue SFC 中使用它:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
假设 some-lib 将其源 TypeScript 文件构建到 dist/ 文件夹中。some-lib 的用户可以像这样导入 SomeElement 并在 Vue SFC 中使用它:
假设 some-lib 将其 TypeScript 源文件构建到 dist/ 文件夹中。some-lib 的用户可以像这样导入 SomeElement 并在 Vue SFC 中使用它:

@@ -446,37 +446,37 @@ onMounted(() => {
el.value!.someMethod()
)
// Do not use these props, they are `undefined` (IDE will show them crossed out):
// 不要使用这些属性,它们是 `undefined` IDE 会将它们显示为删除线):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 不要使用这些属性,它们是 `undefined` (IDE 会将它们显示为删除线):
// 不要使用这些属性,它们是 `undefined`
// IDE 会将它们显示为删除线

Comment on lines +506 to +510
自定义元素的作者不应该从他们的库中自动导出特定框架的自定义元素类型定义,例如他们不应该从 `index.ts` 文件中导出它们,而该文件还导出了库的其余部分,否则用户将会遇到意外的模块扩展错误。用户应该导入他们需要的特定框架的类型定义文件。




Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
自定义元素的作者不应该从他们的库中自动导出特定框架的自定义元素类型定义,例如他们不应该从 `index.ts` 文件中导出它们,而该文件还导出了库的其余部分,否则用户将会遇到意外的模块扩展错误。用户应该导入他们需要的特定框架的类型定义文件。
自定义元素的作者不应该从他们的库中自动导出特定框架的自定义元素类型定义,例如他们不应该同时从 `index.ts` 文件中导出它们以及库的其余部分,否则用户将会遇到意外的模块扩展错误。用户应该导入他们需要的特定框架的类型定义文件。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants