Skip to content
This repository was archived by the owner on Aug 8, 2022. It is now read-only.

Commit c5fbd5b

Browse files
author
Aaron
authored
Merge pull request #3 from vuejs/master
update repo
2 parents ed7a93c + dbb6c47 commit c5fbd5b

15 files changed

+78
-86
lines changed

src/api/application-api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ app.mount('#my-app')
223223

224224
- **用法:**
225225

226-
设置一个可以被注入到应用范围内所有组件中的值。组件应该使用 `inject` 来接收提供的值
226+
设置一个可以被注入到应用范围内所有组件中的值。组件应该使用 `inject` 来接收 provide 的值
227227

228228
`provide`/`inject` 的角度来看,可以将应用程序视为根级别的祖先,而根组件是其唯一的子级。
229229

230-
该方法不应该与 [provide 组件选项](options-composition.html#provide-inject)或组合式 API 中的 [provide 方法](composition-api.html#provide-inject)混淆。虽然它们也是相同的 `provide`/`inject` 机制的一部分,但是是用来配置组件提供的值而不是应用提供的值
230+
该方法不应该与 [provide 组件选项](options-composition.html#provide-inject)或组合式 API 中的 [provide 方法](composition-api.html#provide-inject)混淆。虽然它们也是相同的 `provide`/`inject` 机制的一部分,但是是用来配置组件 provide 的值而不是应用 provide 的值
231231

232232
通过应用提供值在写插件时尤其有用,因为插件一般不能使用组件提供值。这是使用 [globalProperties](application-config.html#globalProperties) 的替代选择。
233233

src/api/composition-api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function inject<T>(
145145
): T
146146
```
147147

148-
Vue 提供了一个 `InjectionKey` 接口,该接口是扩展 `Symbol` 的泛型类型。它可用于在提供者和消费者之间同步注入值的类型
148+
Vue 提供了一个 `InjectionKey` 接口,该接口是扩展 `Symbol` 的泛型类型。它可用于在提供者和消费者之间同步 inject 值的类型
149149

150150
```ts
151151
import { InjectionKey, provide, inject } from 'vue'
@@ -157,7 +157,7 @@ provide(key, 'foo') // 提供非字符串值将导致错误
157157
const foo = inject(key) // foo 的类型: string | undefined
158158
```
159159

160-
如果使用字符串 key 或非类型化 symbols则需要显式声明注入值的类型
160+
如果使用字符串 key 或非类型化 symbols则需要显式声明 inject 值的类型
161161

162162
```ts
163163
const foo = inject<string>('foo') // string | undefined

src/api/options-composition.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171

7272
- 一个字符串数组,或
7373
- 一个对象,对象的 key 是本地的绑定名,value 是:
74-
- 在可用的注入内容中搜索用的 key (字符串或 Symbol),或
74+
- 在可用注入内容中搜索用的 key (字符串或 Symbol),或
7575
- 一个对象,该对象的:
7676
- `from` property 是在可用的注入内容中搜索用的 key (字符串或 Symbol)
7777
- `default` property 是降级情况下使用的 value
@@ -81,15 +81,15 @@
8181
- **示例:**
8282

8383
```js
84-
// 父级组件提供 'foo'
84+
// 父级组件 provide 'foo'
8585
const Provider = {
8686
provide: {
8787
foo: 'bar'
8888
}
8989
// ...
9090
}
9191

92-
// 子组件注入 'foo'
92+
// 子组件 inject 'foo'
9393
const Child = {
9494
inject: ['foo'],
9595
created() {
@@ -118,7 +118,7 @@
118118
}
119119
```
120120

121-
使用一个注入的值作为一个 property 的默认值:
121+
使用一个 inject 的值作为一个 property 的默认值:
122122

123123
```js
124124
const Child = {
@@ -133,7 +133,7 @@
133133
}
134134
```
135135

136-
使用一个注入的值作为数据入口
136+
使用一个 inject 的值作为数据入口
137137

138138
```js
139139
const Child = {
@@ -146,7 +146,7 @@
146146
}
147147
```
148148

149-
注入可以通过设置默认值使其变成可选项
149+
Inject 可以通过设置默认值使其变成可选项
150150

151151
```js
152152
const Child = {

src/api/refs-api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function useFeatureX() {
133133
134134
export default {
135135
setup() {
136-
// 可以在不失去响应性的情况下破坏结构
136+
// 可以在不失去响应性的情况下解构
137137
const { foo, bar } = useFeatureX()
138138
139139
return {
@@ -221,7 +221,7 @@ isReactive(foo.value) // false
221221

222222
## `triggerRef`
223223

224-
手动执行与 `shallowRef`](#shallowref) 关联的任何效果
224+
手动执行与 [`shallowRef`](#shallowref) 关联的任何副作用
225225

226226
```js
227227
const shallow = shallowRef({

src/cookbook/debugging-in-vscode.md

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
1-
<!-- TODO: translation -->
1+
# 在 VS Code 中调试
22

3-
# Debugging in VS Code
3+
每个应用,不论大小,都需要理解程序是为何运行失败的。在本案例中,我们会探索一些 VS Code 用户在浏览器中调试应用的工作流程。
44

5-
Every application reaches a point where it's necessary to understand failures, small to large. In this recipe, we explore a few workflows for VS Code users who would like to debug their application in the browser.
5+
这个案例展示了如何在 VS Code 中调试浏览器中运行的通过 [Vue CLI](https://github.com/vuejs/vue-cli) 生成的 Vue.js 应用。
66

7-
This recipe shows how to debug [Vue CLI](https://github.com/vuejs/vue-cli) applications in VS Code as they run in the browser.
7+
## 先决条件
88

9-
## Prerequisites
10-
11-
Make sure you have VS Code and the browser of your choice installed, and the latest version of the corresponding Debugger extension installed and enabled:
9+
请确保你安装了 VS Code 以及适合的浏览器,并且安装激活了最新版的相应的 Debugger 扩展:
1210

1311
- [Debugger for Chrome](https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome)
1412
- [Debugger for Firefox](https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-firefox-debug)
1513

16-
Install and create a project with the [vue-cli](https://github.com/vuejs/vue-cli), following the instructions in the [Vue CLI Guide](https://cli.vuejs.org/). Change into the newly created application directory and open VS Code.
14+
请通过 [vue-cli](https://github.com/vuejs/vue-cli),遵循它的 [Vue CLI 教程](https://cli.vuejs.org/)并创建一个项目。然后进入这个新创建的应用的目录,打开 VS Code
1715

18-
### Displaying Source Code in the Browser
16+
### 在浏览器中展示源代码
1917

20-
Before you can debug your Vue components from VS Code, you need to update the generated Webpack config to build sourcemaps. We do this so that our debugger has a way to map the code within a compressed file back to its position in the original file. This ensures that you can debug an application even after your assets have been optimized by Webpack.
18+
在可以从 VS Code 调试你的 Vue 组件之前,你需要更新 Webpack 配置以构建 source map。做了这件事之后,我们的调试器就有机会将一个被压缩的文件中的代码对应回其源文件相应的位置。这会确保你可以在一个应用中调试,即便你的资源已经被 Webpack 优化过了也没关系。
2119

22-
If you use Vue CLI 2, set or update the `devtool` property inside `config/index.js`:
20+
如果你使用的是 Vue CLI 2,请设置并更新 `config/index.js` 内的 `devtool` property:
2321

2422
```json
2523
devtool: 'source-map',
2624
```
2725

28-
If you use Vue CLI 3, set or update the `devtool` property inside `vue.config.js`:
26+
如果你使用的是 Vue CLI 3,请设置并更新 `vue.config.js` 内的 `devtool` property:
2927

3028
```js
3129
module.exports = {
@@ -35,15 +33,15 @@ module.exports = {
3533
}
3634
```
3735

38-
### Launching the Application from VS Code
36+
### VS Code 启动应用
3937

4038
::: info
41-
We're assuming the port to be `8080` here. If it's not the case (for instance, if `8080` has been taken and Vue CLI automatically picks another port for you), just modify the configuration accordingly.
39+
我们这里假设端口号为 `8080`。如果与实际情况不符 (比如 `8080` 端口已经被占用且 Vue CLI 为你自动选取了另一个端口号),可以修改相应的配置。
4240
:::
4341

44-
Click on the Debugging icon in the Activity Bar to bring up the Debug view, then click on the gear icon to configure a launch.json file, selecting **Chrome/Firefox: Launch** as the environment. Replace content of the generated launch.json with the corresponding configuration:
42+
点击在 Activity Bar 里的 Debugger 图标来到 Debug 视图,然后点击那个齿轮图标来配置一个 launch.json 的文件,选择 **Chrome/Firefox: Launch** 环境。然后将生成的 launch.json 的内容替换成为相应的配置:
4543

46-
![Add Chrome Configuration](/images/config_add.png)
44+
![添加 Chrome 配置](/images/config_add.png)
4745

4846
```json
4947
{
@@ -72,37 +70,37 @@ Click on the Debugging icon in the Activity Bar to bring up the Debug view, then
7270
}
7371
```
7472

75-
## Setting a Breakpoint
73+
## 设置一个断点
7674

77-
1. Set a breakpoint in **src/components/HelloWorld.vue** on `line 90` where the `data` function returns a string.
75+
1. **src/components/HelloWorld.vue** `line 90` 的地方设置一个断点,这里的 `data` 函数返回一个字符串。
7876

79-
![Breakpoint Renderer](/images/breakpoint_set.png)
77+
![断点渲染器](/images/breakpoint_set.png)
8078

81-
2. Open your favorite terminal at the root folder and serve the app using Vue CLI:
79+
2. 在根目录打开你惯用的终端并使用 Vue CLI 开启这个应用:
8280

8381
```
8482
npm run serve
8583
```
8684

87-
3. Go to the Debug view, select the **'vuejs: chrome/firefox'** configuration, then press F5 or click the green play button.
85+
3. 来到 Debug 视图,选择 **vuejs: chrome/firefox** 配置,然后按 F5 或点击那个绿色的 play 按钮。
8886

89-
4. Your breakpoint should now be hit as a new browser instance opens `http://localhost:8080`.
87+
4. 随着一个新的浏览器实例打开 `http://localhost:8080`,你的断点现在应该被命中了。
9088

91-
![Breakpoint Hit](/images/breakpoint_hit.png)
89+
![命中断点](/images/breakpoint_hit.png)
9290

93-
## Alternative Patterns
91+
## 替代方案
9492

9593
### Vue Devtools
9694

97-
There are other methods of debugging, varying in complexity. The most popular and simple of which is to use the excellent Vue.js devtools [for Chrome](https://chrome.google.com/webstore/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd) and [for Firefox](https://addons.mozilla.org/en-US/firefox/addon/vue-js-devtools/). Some of the benefits of working with the devtools are that they enable you to live-edit data properties and see the changes reflected immediately. The other major benefit is the ability to do time travel debugging for Vuex.
95+
我们还有一些其它的调试方法,复杂度不尽相同。其中最流行和简单的是使用非常棒的 [Chrome 版本](https://chrome.google.com/webstore/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd)[Firefox 版本](https://addons.mozilla.org/en-US/firefox/addon/vue-js-devtools/)的 Vue.js devtools。使用 devtools 有很多好处,比如它可以让你能够实时编辑数据 property 并立即看到其反映出来的变化。另一个主要的好处是能够为 Vuex 提供时间旅行式的调试体验。
9896

9997
![Devtools Timetravel Debugger](/images/devtools-timetravel.gif)
10098

101-
Please note that if the page uses a production/minified build of Vue.js (such as the standard link from a CDN), devtools inspection is disabled by default so the Vue pane won't show up. If you switch to an unminified version, you may have to give the page a hard refresh to see them.
99+
请留意如果页面使用了一个生产环境/压缩后的 Vue.js 构建版本 (例如来自一个 CDN 的标准的链接),devtools 的审查功能是默认被禁用的,所以 Vue 面板不会出现。如果你切换到一个非压缩版本,你可能需要强制刷新该页面来看到它。
102100

103-
### Simple Debugger Statement
101+
### 简单的 debugger 语句
104102

105-
The example above has a great workflow. However, there is an alternative option where you can use the [native debugger statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger) directly in your code. If you choose to work this way, it's important that you remember to remove the statements when you're done.
103+
上述示例的工作流程非常好。不过这里还有一个替代选项,就是你可以直接在代码中使用[原生的 debugger 语句](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/debugger)。如果你选择了这种方式,请千万记得当你调试完毕之后把这个语句移除。
106104

107105
```js
108106
<script>
@@ -121,6 +119,6 @@ export default {
121119
</script>
122120
```
123121

124-
## Acknowledgements
122+
## 致谢
125123

126-
This recipe was based on a contribution from [Kenneth Auchenberg](https://twitter.com/auchenberg), [available here](https://github.com/Microsoft/VSCode-recipes/tree/master/vuejs-cli).
124+
这个案例是基于 [Kenneth Auchenberg](https://twitter.com/auchenberg) 贡献的,[可在此](https://github.com/Microsoft/VSCode-recipes/tree/master/vuejs-cli) 阅读。

src/cookbook/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Cookbook 为开发者提供了一些示例,涵盖常见的或有趣的用例
4242
3. 显示一小段代码示例。
4343
4. 用一句话解释它完成了什么。
4444

45-
### 关于其价值的细节 <Badge text="必要的" type="error" />
45+
### 关于其值的细节 <Badge text="必要的" type="error" />
4646

4747
1. 解决人们在看例子时可能遇到的常见问题。(最好以块引用格式呈现)
4848
2. 显示常见错误的例子,以及如何避免它们。

src/guide/component-basics.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ app.mount('#components-demo')
3939
```
4040
<common-codepen-snippet title="Component basics" slug="abORVEJ" tab="js,result" :preview="false" />
4141

42-
因为组件是可复用的组件实例,所以它们与根实例接收相同的选项,例如 `data``computed``watch``methods` 以及生命周期钩子等。仅有的例外是像 `el` 这样根实例特有的选项。
42+
因为组件是可复用的组件实例,所以它们与根实例接收相同的选项,例如 `data``computed``watch``methods` 以及生命周期钩子等。
4343

4444
## 组件的复用
4545

@@ -55,7 +55,7 @@ app.mount('#components-demo')
5555

5656
<common-codepen-snippet title="Component basics: reusing components" slug="rNVqYvM" tab="html,result" :preview="false" />
5757

58-
注意当点击按钮时,每个组件都会各自独立维护它的 `count`。因为你每用一次组件,就会有一个它的**新实例**被创建。
58+
注意当点击按钮时,每个组件都会各自独立维护它的 `count`。因为你每用一次组件,就会有一个它的新**实例**被创建。
5959

6060
## 组件的组织
6161

@@ -83,7 +83,7 @@ app.component('my-component-name', {
8383

8484
早些时候,我们提到了创建一个博文组件的事情。问题是如果你不能向这个组件传递某一篇博文的标题或内容之类的我们想展示的数据的话,它是没有办法使用的。这也正是 prop 的由来。
8585

86-
Prop 是你可以在组件上注册的一些自定义 attribute。当一个值传递给一个 prop attribute 的时候,它就变成了那个组件实例的一个 property。为了给博文组件传递一个标题,我们可以用一个 props 选项将其包含在该组件可接受的 `prop` 列表中:
86+
Prop 是你可以在组件上注册的一些自定义 attribute。为了给博文组件传递一个标题,我们可以用一个 props 选项将其包含在该组件可接受的 `prop` 列表中:
8787

8888
```js
8989
const app = Vue.createApp({})
@@ -289,7 +289,7 @@ methods: {
289289
```
290290

291291
::: warning
292-
请注意,我们在这里使用的是 `model value`,因为我们使用的是 DOM 模板中的 kebab-case。你可以在 [DOM Template Parsing Caveats](#dom-template-parsing-caveats) 部分找到关于 kebab cased 和 camelCased 属性的详细说明
292+
请注意,我们在这里使用的是 `model-value`,因为我们使用的是 DOM 模板中的 kebab-case。你可以在 [DOM Template Parsing Caveats](#dom-template-parsing-caveats) 部分找到关于 kebab cased 和 camelCased 属性的详细说明
293293
:::
294294

295295
为了让它正常工作,这个组件内的 `<input>` 必须:
@@ -396,7 +396,7 @@ app.component('alert-box', {
396396

397397
你可以在[这里](https://codepen.io/team/Vue/pen/oNXaoKy)查阅并体验完整的代码,或在[这个版本](https://codepen.io/team/Vue/pen/oNXapXM)了解绑定组件选项对象,而不是已注册组件名的示例。
398398

399-
请留意,这个 attribute 可以用于常规 HTML 元素,但这些元素将被视为组件,这意味着所有的 attribute **都会作为 DOM attribute 被绑定**。对于像 `value` 这样的 property,若想让其如预期般工作,你需要使用 [.prop 修饰器](../api/directives.html#v-bind)
399+
你也可以使用 `is` attribute 来创建常规的 HTML 元素
400400

401401
到目前为止,关于动态组件你需要了解的大概就这些了,如果你阅读完本页内容并掌握了它的内容,我们会推荐你再回来把[动态 & 异步组件](./components-dynamic-async.html)读完。
402402

src/guide/component-provide-inject.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# 提供 / 注入
1+
# Provide / Inject
22

33
> 该页面假设你已经阅读过了[组件基础](component-basics.md)。如果你还对组件不太了解,推荐你先阅读它。
44
55
通常,当我们需要将数据从父组件传递到子组件时,我们使用 [props](component-props.md)。想象一下这样的结构:你有一些深嵌套的组件,而你只需要来自深嵌套子组件中父组件的某些内容。在这种情况下,你仍然需要将 prop 传递到整个组件链中,这可能会很烦人。
66

7-
对于这种情况,我们可以使用 `provide``inject` 对。父组件可以作为其所有子组件的依赖项提供程序,而不管组件层次结构有多深。这个特性有两个部分:父组件有一个 `provide` 选项来提供数据,子组件有一个 `inject` 选项来开始使用这个数据。
7+
对于这种情况,我们可以使用一对 `provide``inject`。父组件可以作为其所有子组件的依赖项提供函数,而不管组件层次结构有多深。这个特性有两个部分:父组件有一个 `provide` 选项来提供数据,子组件有一个 `inject` 选项来开始使用这个数据。
88

99
![Provide/inject scheme](/images/components_provide.png)
1010

@@ -49,7 +49,7 @@ app.component('todo-list-statistics', {
4949
})
5050
```
5151

52-
但是,如果我们尝试在此处提供一些组件实例 property,则这将不起作用:
52+
但是,如果我们尝试在此处 provide 一些组件实例 property,则这将不起作用:
5353

5454
```js
5555
app.component('todo-list', {
@@ -59,7 +59,7 @@ app.component('todo-list', {
5959
}
6060
},
6161
provide: {
62-
todoLength: this.todos.length // 将会导致错误 'Cannot read property 'length' of undefined`
62+
todoLength: this.todos.length // 将会导致错误 `Cannot read property 'length' of undefined`
6363
},
6464
template: `
6565
...
@@ -91,12 +91,12 @@ app.component('todo-list', {
9191

9292
实际上,你可以将依赖注入看作是“long range props”,除了:
9393

94-
- 父组件不需要知道哪些子组件使用它提供的 property
94+
- 父组件不需要知道哪些子组件使用它 provide 的 property
9595
- 子组件不需要知道 `inject` property 来自哪里
9696

9797
## 处理响应性
9898

99-
在上面的例子中,如果我们更改了 `todos` 的列表,这个更改将不会反映在注入的 `todoLength` property 中。这是因为默认情况下,`provide/inject` 绑定**是被动绑定。我们可以通过将 `ref` property 或 `reactive` 对象传递给 `provide` 来更改此行为。在我们的例子中,如果我们想对祖先组件中的更改做出反应,我们需要为我们提供的 `todoLength` 分配一个组合式 API `computed` property:
99+
在上面的例子中,如果我们更改了 `todos` 的列表,这个更改将不会反映在 inject 的 `todoLength` property 中。这是因为默认情况下,`provide/inject` 绑定**是被动绑定。我们可以通过将 `ref` property 或 `reactive` 对象传递给 `provide` 来更改此行为。在我们的例子中,如果我们想对祖先组件中的更改做出反应,我们需要为我们 provide 的 `todoLength` 分配一个组合式 API `computed` property:
100100

101101
```js
102102
app.component('todo-list', {

src/guide/component-slots.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Vue 实现了一套内容分发的 API,这套 API 的设计灵感源自 [Web C
114114
</button>
115115
```
116116

117-
现在当我在一个父级组件中使用 `<submit-button` > 并且不提供任何插槽内容时:
117+
现在当我们在一个父级组件中使用 `<submit-button` > 并且不提供任何插槽内容时:
118118

119119
```html
120120
<submit-button></submit-button>

0 commit comments

Comments
 (0)