Skip to content

Commit 6dcaf02

Browse files
committed
[docs][zh] translated spec.md
1 parent 14f1336 commit 6dcaf02

File tree

1 file changed

+35
-36
lines changed

1 file changed

+35
-36
lines changed

docs/zh/spec.md

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
2-
title: SFC Spec
2+
title: 单文件组件规范
33
sidebar: auto
44
---
55

6-
# Vue Single-File Component (SFC) Spec
6+
# Vue 单文件组件 (SFC) 规范
77

8-
## Intro
8+
## 简介
99

10-
A `*.vue` file is a custom file format that uses HTML-like syntax to describe a Vue component. Each `*.vue` file consists of three types of top-level language blocks: `<template>`, `<script>`, and `<style>`, and optionally additional custom blocks:
10+
`.vue` 文件是一个自定义的文件类型,用类 HTML 语法描述一个 Vue 组件。每个 `.vue` 文件包含三种类型的顶级语言块 `<template>``<script>` `<style>`,还允许添加可选的自定义块:
1111

1212
``` vue
1313
<template>
@@ -35,82 +35,82 @@ export default {
3535
</custom1>
3636
```
3737

38-
`vue-loader` will parse the file, extract each language block, pipe them through other loaders if necessary, and finally assemble them back into an ES Module whose default export is a Vue.js component options object.
38+
`vue-loader` 会解析文件,提取每个语言块,如有必要会通过其它 loader 处理,最后将他们组装成一个 ES Module,它的默认导出是一个 Vue.js 组件选项的对象。
3939

40-
`vue-loader` supports using non-default languages, such as CSS pre-processors and compile-to-HTML template languages, by specifying the `lang` attribute for a language block. For example, you can use Sass for the style of your component like this:
40+
`vue-loader` 支持使用非默认语言,比如 CSS 预处理器,预编译的 HTML 模版语言,通过设置语言块的 `lang` 属性。例如,你可以像下面这样使用 Sass 语法编写样式:
4141

4242
``` vue
4343
<style lang="sass">
4444
/* write Sass! */
4545
</style>
4646
```
4747

48-
More details can be found in [Using Pre-Processors](./pre-processors.md).
48+
更多细节可以在[使用预处理器](./pre-processors.md)中找到。
4949

50-
## Language Blocks
50+
## 语言块
5151

52-
### Template
52+
### 模板
5353

54-
- Each `*.vue` file can contain at most one `<template>` block at a time.
54+
- 每个 `.vue` 文件最多包含一个 `<template>` 块。
5555

56-
- Contents will be extracted and passed on to `vue-template-compiler` and pre-compiled into JavaScript render functions, and finally injected into the exported component in the `<script>` section.
56+
- 内容将被提取并传递给 `vue-template-compiler` 为字符串,预处理为 JavaScript 渲染函数,并最终注入到从 `<script>` 导出的组件中。
5757

58-
### Script
58+
### 脚本
5959

60-
- Each `*.vue` file can contain at most one `<script>` block at a time.
60+
- 每个 `.vue` 文件最多包含一个 `<script>` 块。
6161

62-
- The script is executed as an ES Module.
62+
- 这个脚本会作为一个 ES Module 来执行。
6363

64-
- The **default export** should be a Vue.js [component options object](https://vuejs.org/v2/api/#Options-Data). Exporting an extended constructor created by `Vue.extend()` is also supported, but a plain object is preferred.
64+
- 它的**默认导出**应该是一个 Vue.js [组件选项对象](https://cn.vuejs.org/v2/api/#选项-数据)。也可以导出由 `Vue.extend()` 创建的扩展对象,但是普通对象是更好的选择。
6565

66-
- Any webpack rules that match against `.js` files (or the extension specified by the `lang` attribute) will be applied to contents in the `<script>` block as well.
66+
- 任何匹配 `.js` 文件 (或通过它的 `lang` 特性指定的扩展名) 的 webpack 规则都将会运用到这个 `<script>` 块的内容中。
6767

68-
### Style
68+
### 样式
6969

70-
- Default match: `/\.css$/`.
70+
- 默认匹配:`/\.css$/`
7171

72-
- A single `*.vue` file can contain multiple `<style>` tags.
72+
- 一个 `.vue` 文件可以包含多个 `<style>` 标签。
7373

74-
- A `<style>` tag can have `scoped` or `module` attributes (see [Scoped CSS](./scoped-css.md) and [CSS Modules](./css-modules.md)) to help encapsulate the styles to the current component. Multiple `<style>` tags with different encapsulation modes can be mixed in the same component.
74+
- `<style>` 标签可以有 `scoped` 或者 `module` 属性 (查看 [CSS 作用域](./scoped-css.md)[CSS Modules](./css-modules.md)) 以帮助你将样式封装到当前组件。具有不同封装模式的多个 `<style>` 标签可以在同一个组件中混合使用。
7575

76-
- Any webpack rules that match against `.css` files (or the extension specified by the `lang` attribute) will be applied to contents in the `<style>` blocks as well.
76+
- 任何匹配 `.css` 文件 (或通过它的 `lang` 特性指定的扩展名) 的 webpack 规则都将会运用到这个 `<style>` 块的内容中。
7777

78-
### Custom Blocks
78+
### 自定义块
7979

80-
Additional custom blocks can be included in a `*.vue` file for any project specific needs, for example a `<docs>` block. `vue-loader` will use the tag name to look up which webpack loaders should be applied to the contents of the section. The webpack loaders should be specified in the `loaders` section of `vue-loader` options.
80+
可以在 `.vue` 文件中添加额外的自定义块来实现项目的特定需求,例如 `<docs>` 块。`vue-loader` 将会使用标签名来查找对应的 webpack loader 来应用在对应的块上。webpack loader 需要在 `vue-loader` 的选项 `loaders` 中指定。
8181

82-
For mode details, see [Custom Blocks](./custom-blocks.md).
82+
更多细节,查看[自定义块](./custom-blocks.md)
8383

84-
### Src Imports
84+
### Src 导入
8585

86-
If you prefer splitting up your `*.vue` components into multiple files, you can use the `src` attribute to import an external file for a language block:
86+
如果你喜欢分隔你的 `.vue` 文件到多个文件中,你可以通过 `src` 属性导入外部文件:
8787

8888
``` vue
8989
<template src="./template.html"></template>
9090
<style src="./style.css"></style>
9191
<script src="./script.js"></script>
9292
```
9393

94-
Beware that `src` imports follow the same path resolution rules to webpack module requests, which means:
94+
需要注意的是 `src` 导入遵循和 webpack 模块请求相同的路径解析规则,这意味着:
9595

96-
- Relative paths need to start with `./`
97-
- You can import resources from npm dependencies:
96+
- 相对路径需要以 `./` 开始
97+
- 你可以从 NPM 依赖中导入资源:
9898

9999
``` vue
100100
<!-- import a file from the installed "todomvc-app-css" npm package -->
101101
<style src="todomvc-app-css/index.css">
102102
```
103103

104-
`src` imports also work with custom blocks, e.g.:
104+
在自定义块上同样支持 `src` 导入,例如:
105105

106106
``` vue
107107
<unit-test src="./unit-test.js">
108108
</unit-test>
109109
```
110110

111-
## Syntax Highlighting / IDE Support
111+
## 语法高亮 / IDE 支持
112112

113-
Currently there is syntax highlighting support for the following IDE/editors:
113+
目前有下列 IDE/编辑器 支持语法高亮:
114114

115115
- [Sublime Text](https://github.com/vuejs/vue-syntax-highlight)
116116
- [VS Code](https://marketplace.visualstudio.com/items?itemName=octref.vetur)
@@ -120,9 +120,8 @@ Currently there is syntax highlighting support for the following IDE/editors:
120120
- [Brackets](https://github.com/pandao/brackets-vue)
121121
- [JetBrains IDEs](https://plugins.jetbrains.com/plugin/8057) (WebStorm, PhpStorm, etc)
122122

123-
Contributions for other editors/IDEs are highly appreciated! If you are not using any pre-processors in Vue components, you can also get decent syntax highlighting by treating `*.vue` files as HTML in your editor.
123+
非常感谢其他编辑器/IDE 所做的贡献!如果在 Vue 组件中没有使用任何预处理器,你可以把 `.vue` 文件当作 HTML 对待。
124124

125-
## Comments
126-
127-
Inside each block you shall use the comment syntax of the language being used (HTML, CSS, JavaScript, Jade, etc). For top-level comments, use HTML comment syntax: `<!-- comment contents here -->`
125+
## 注释
128126

127+
在语言块中使用该语言块对应的注释语法 (HTML、CSS、JavaScript、Jade 等)。顶层注释使用 HTML 注释语法:`<!-- comment contents here -->`

0 commit comments

Comments
 (0)