You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/zh/guide/css-modules.md
+22-22Lines changed: 22 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,27 +1,27 @@
1
1
# CSS Modules
2
2
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.
@@ -32,7 +32,7 @@ First, CSS Modules must be enabled by passing `modules: true` to `css-loader`:
32
32
}
33
33
```
34
34
35
-
Then, add the `module` attribute to your `<style>`:
35
+
然后在你的 `<style>` 上添加 `module` 特性:
36
36
37
37
```vue
38
38
<style module>
@@ -45,7 +45,7 @@ Then, add the `module` attribute to your `<style>`:
45
45
</style>
46
46
```
47
47
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:
@@ -55,7 +55,7 @@ The `module` attribute instructs Vue Loader to inject the CSS modules locals obj
55
55
</template>
56
56
```
57
57
58
-
Since it's a computed property, it also works with the object/array syntax of `:class`:
58
+
因为这是一个计算属性,所以它也支持 `:class` 的对象/数组语法:
59
59
60
60
```vue
61
61
<template>
@@ -70,32 +70,32 @@ Since it's a computed property, it also works with the object/array syntax of `:
70
70
</template>
71
71
```
72
72
73
-
And you can also access it from JavaScript:
73
+
你也可以通过 JavaScript 访问到它:
74
74
75
75
```vue
76
76
<script>
77
77
export default {
78
78
created () {
79
79
console.log(this.$style.red)
80
80
// -> "red_1VyoJ-uZ"
81
-
// an identifier generated based on filename and className.
81
+
// 一个基于文件名和类名生成的标识符
82
82
}
83
83
}
84
84
</script>
85
85
```
86
86
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).
@@ -109,7 +109,7 @@ If you only want to use CSS Modules in some of your Vue components, you can use
109
109
}
110
110
]
111
111
},
112
-
//this matches plain <style> or <style scoped>
112
+
//这里匹配普通的 `<style>` 或 `<style scoped>`
113
113
{
114
114
use: [
115
115
'vue-style-loader',
@@ -120,9 +120,9 @@ If you only want to use CSS Modules in some of your Vue components, you can use
120
120
}
121
121
```
122
122
123
-
## Using with Pre-Processors
123
+
## 和预处理器配合使用
124
124
125
-
CSS Modules can be used along with other pre-processors:
125
+
CSS Modules 可以独立用于其它预处理器:
126
126
127
127
```js
128
128
// webpack.config.js -> module.rules
@@ -139,16 +139,16 @@ CSS Modules can be used along with other pre-processors:
139
139
}
140
140
```
141
141
142
-
## Custom Inject Name
142
+
## 自定义的注入名称
143
143
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:
0 commit comments