-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
base: main
Are you sure you want to change the base?
Update web-components.md #1063
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -301,102 +301,92 @@ declare module 'vue' { | |||
``` | |||
|
|||
## 非 Vue Web Components 和 TypeScript {#non-vue-web-components-and-typescript} | |||
<!-- TODO: translation --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请尽量保持译文与原文每段占用的行数一致,有助于以后的更新同步不易错乱,见翻译须知
此处 TODO 应为空行,其他位置的改动同理
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哦哦好,谢谢提醒,祝你元宵节快乐 ^_^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可能是我的表达有误,不是指通过添加空行来保持行号一致,不过刚刚发现上游已经调整了格式,可以直接参照上游最新的格式保持段落行号,抱歉🙏
稍后我会 review 并且提出修改建议
There was a problem hiding this 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 的格式更改
// 请务必在此处输入 Vue 组件类型(SomeComponent,*而不是* SomeElement)。 | ||
// 自定义元素的名称中需要连字符,因此请在此处使用连字符元素名称。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 请务必在此处输入 Vue 组件类型(SomeComponent,*而不是* SomeElement)。 | |
// 自定义元素的名称中需要连字符,因此请在此处使用连字符元素名称。 | |
// 请务必在此处输入 Vue 组件类型 | |
// (SomeComponent,*而不是* SomeElement)。 | |
// 自定义元素的名称中需要连字符, | |
// 因此请在此处使用连字符元素名称。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这样修改了后面的行号不就不对应了嘛
There was a problem hiding this comment.
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
|
||
以下是在非Vue构建的自定义元素的SFC模板中启用类型检查的推荐方法。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
以下是在非Vue构建的自定义元素的SFC模板中启用类型检查的推荐方法。 | |
以下是在非 Vue 构建的自定义元素的 SFC 模板中启用类型检查的推荐方法。 |
|
||
假设我们有一个自定义元素,其中定义了一些 JS 属性和事件,并且它被包含在一个名为 `some-lib`的库中: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
假设我们有一个自定义元素,其中定义了一些 JS 属性和事件,并且它被包含在一个名为 `some-lib`的库中: | |
假设我们有一个自定义元素,其中定义了一些 JS 属性和事件,并且它发布在名为 `some-lib` 的库中: |
实现细节已经省略,但重要的是我们有两个东西的类型定义:属性类型和事件类型。 | ||
|
||
|
||
让我们创建一个类型助手,以便在 Vue 中轻松注册自定义元素类型定义: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
实现细节已经省略,但重要的是我们有两个东西的类型定义:属性类型和事件类型。 | |
让我们创建一个类型助手,以便在 Vue 中轻松注册自定义元素类型定义: | |
实现细节已省略,重点是我们为两个东西提供了类型定义:prop 类型和事件类型。 | |
让我们创建一个类型工具,以便在 Vue 中轻松注册自定义元素类型定义: |
// Vue 特别从 `$props` 类型读取属性定义 | ||
// 请注意,我们将元素的属性与全局 HTML 属性和 Vue 的特殊属性结合在一起 | ||
|
||
/** @deprecated 不要在自定义元素引用上使用 $props 属性,这仅用于模板属性类型检查 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** @deprecated 不要在自定义元素引用上使用 $props 属性,这仅用于模板属性类型检查 */ | |
/** @deprecated 不要在自定义元素引用上使用 $props 属性, | |
这仅用于模板属性类型检查 */ |
// 使用 $emit 专门定义事件类型 | ||
// Vue 特别从 `$emit` 类型读取事件类型 | ||
// 请注意,`$emit` 期望我们将 `Events` 映射到特定格式 | ||
/** @deprecated 不要在自定义元素引用上使用 $emit 属性,这仅用于模板属性类型检查 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** @deprecated 不要在自定义元素引用上使用 $emit 属性,这仅用于模板属性类型检查 */ | |
/** @deprecated 不要在自定义元素引用上使用 $emit 属性, | |
这仅用于模板属性类型检查 */ |
假设 some-lib 将其源 TypeScript 文件构建到 dist/ 文件夹中。some-lib 的用户可以像这样导入 SomeElement 并在 Vue SFC 中使用它: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
假设 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 会将它们显示为删除线): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 不要使用这些属性,它们是 `undefined` (IDE 会将它们显示为删除线): | |
// 不要使用这些属性,它们是 `undefined` | |
// IDE 会将它们显示为删除线 |
自定义元素的作者不应该从他们的库中自动导出特定框架的自定义元素类型定义,例如他们不应该从 `index.ts` 文件中导出它们,而该文件还导出了库的其余部分,否则用户将会遇到意外的模块扩展错误。用户应该导入他们需要的特定框架的类型定义文件。 | ||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
自定义元素的作者不应该从他们的库中自动导出特定框架的自定义元素类型定义,例如他们不应该从 `index.ts` 文件中导出它们,而该文件还导出了库的其余部分,否则用户将会遇到意外的模块扩展错误。用户应该导入他们需要的特定框架的类型定义文件。 | |
自定义元素的作者不应该从他们的库中自动导出特定框架的自定义元素类型定义,例如他们不应该同时从 `index.ts` 文件中导出它们以及库的其余部分,否则用户将会遇到意外的模块扩展错误。用户应该导入他们需要的特定框架的类型定义文件。 |
在创建 pull request 之前
请确认:
问题描述
翻译了web-components.md