Skip to content

Commit 1f5eef9

Browse files
committed
[docs][zh] translated css-modules.md
1 parent 8b1cc80 commit 1f5eef9

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

docs/zh/guide/css-modules.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
# CSS Modules
22

3-
[CSS Modules](https://github.com/css-modules/css-modules) is a popular system for modularizing and composing CSS. `vue-loader` provides first-class integration with CSS Modules as an alternative for simulated scoped CSS.
3+
[CSS Modules](https://github.com/css-modules/css-modules)是一个用于模块化和组合 CSS 的流行系统。`vue-loader` 提供了与 CSS 模块的一流集成,可以作为模拟 CSS 作用域的替代方案。
44

5-
## Usage
5+
## 用法
66

7-
First, CSS Modules must be enabled by passing `modules: true` to `css-loader`:
7+
首先,CSS Modules 必须通过向 `css-loader` 传入 `modules: true` 来开启:
88

99
``` js
1010
// webpack.config.js
1111
{
1212
module: {
1313
rules: [
14-
// ... other rules omitted
14+
// ... 其它规则省略
1515
{
1616
test: /\.css$/,
1717
use: [
1818
'vue-style-loader',
1919
{
2020
loader: 'css-loader',
2121
options: {
22-
// enable CSS Modules
22+
// 开启 CSS Modules
2323
modules: true,
24-
// customize generated class names
24+
// 自定义生成的类名
2525
localIdentName: '[local]_[hash:base64:8]'
2626
}
2727
}
@@ -32,7 +32,7 @@ First, CSS Modules must be enabled by passing `modules: true` to `css-loader`:
3232
}
3333
```
3434

35-
Then, add the `module` attribute to your `<style>`:
35+
然后在你的 `<style>` 上添加 `module` 特性:
3636

3737
``` vue
3838
<style module>
@@ -45,7 +45,7 @@ Then, add the `module` attribute to your `<style>`:
4545
</style>
4646
```
4747

48-
The `module` attribute instructs Vue Loader to inject the CSS modules locals object into the component as a computed property with the name `$style`. You can then use it in your templates with a dynamic class binding:
48+
这个 `module` 特性指引 Vue Loader 作为名为 `$style` 的计算属性,向组件注入 CSS Modules 局部对象。然后你就可以在模板中通过一个动态类绑定来使用它了:
4949

5050
``` vue
5151
<template>
@@ -55,7 +55,7 @@ The `module` attribute instructs Vue Loader to inject the CSS modules locals obj
5555
</template>
5656
```
5757

58-
Since it's a computed property, it also works with the object/array syntax of `:class`:
58+
因为这是一个计算属性,所以它也支持 `:class` 的对象/数组语法:
5959

6060
``` vue
6161
<template>
@@ -70,32 +70,32 @@ Since it's a computed property, it also works with the object/array syntax of `:
7070
</template>
7171
```
7272

73-
And you can also access it from JavaScript:
73+
你也可以通过 JavaScript 访问到它:
7474

7575
``` vue
7676
<script>
7777
export default {
7878
created () {
7979
console.log(this.$style.red)
8080
// -> "red_1VyoJ-uZ"
81-
// an identifier generated based on filename and className.
81+
// 一个基于文件名和类名生成的标识符
8282
}
8383
}
8484
</script>
8585
```
8686

87-
Refer to the [CSS Modules spec](https://github.com/css-modules/css-modules) for mode details such as [global exceptions](https://github.com/css-modules/css-modules#exceptions) and [composition](https://github.com/css-modules/css-modules#composition).
87+
你可以查阅 [CSS Modules 规范](https://github.com/css-modules/css-modules)了解更多细节,诸如 [global exceptions](https://github.com/css-modules/css-modules#exceptions) [composition](https://github.com/css-modules/css-modules#composition) 等。
8888

89-
## Opt-in Usage
89+
## 可选加入的用法
9090

91-
If you only want to use CSS Modules in some of your Vue components, you can use a `oneOf` rule and check for the `module` string in resourceQuery:
91+
如果你只想在某些 Vue 组件中使用 CSS Modules,你可以使用 `oneOf` 规则并在 `resourceQuery` 字符串中检查 `module` 字符串:
9292

9393
``` js
9494
// webpack.config.js -> module.rules
9595
{
9696
test: /\.css$/,
9797
oneOf: [
98-
// this matches <style module>
98+
// 这里匹配 `<style module>`
9999
{
100100
resourceQuery: /module/,
101101
use: [
@@ -109,7 +109,7 @@ If you only want to use CSS Modules in some of your Vue components, you can use
109109
}
110110
]
111111
},
112-
// this matches plain <style> or <style scoped>
112+
// 这里匹配普通的 `<style>` 或 `<style scoped>`
113113
{
114114
use: [
115115
'vue-style-loader',
@@ -120,9 +120,9 @@ If you only want to use CSS Modules in some of your Vue components, you can use
120120
}
121121
```
122122

123-
## Using with Pre-Processors
123+
## 和预处理器配合使用
124124

125-
CSS Modules can be used along with other pre-processors:
125+
CSS Modules 可以独立用于其它预处理器:
126126

127127
``` js
128128
// webpack.config.js -> module.rules
@@ -139,16 +139,16 @@ CSS Modules can be used along with other pre-processors:
139139
}
140140
```
141141

142-
## Custom Inject Name
142+
## 自定义的注入名称
143143

144-
You can have more than one `<style>` tags in a single `*.vue` component. To avoid injected styles to overwrite each other, you can customize the name of the injected computed property by giving the `module` attribute a value:
144+
`.vue` 中你可以定义不止一个 `<style>`,为了避免被覆盖,你可以通过设置 `module` 属性来为它们定义注入后计算属性的名称。
145145

146146
``` html
147147
<style module="a">
148-
/* identifiers injected as a */
148+
/* 注入标识符 a */
149149
</style>
150150

151151
<style module="b">
152-
/* identifiers injected as b */
152+
/* 注入标识符 b */
153153
</style>
154154
```

0 commit comments

Comments
 (0)