Skip to content

Commit 4f2e3e9

Browse files
committed
docs: add how does it work
1 parent c411066 commit 4f2e3e9

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

README.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- [Use with webpack](#use-with-webpack)
2727
- [Use with Vue CLI](#use-with-vue-cli)
2828
- [Use with Poi](#use-with-poi)
29+
- [How does it work](#how-does-it-work)
2930
- [CSS Preprocessors](#css-preprocessors)
3031
- [Global Styles](#global-styles)
3132
- [TypeScript](#typescript)
@@ -114,15 +115,68 @@ module.exports = {
114115

115116
Guess what, it's the same as Vue CLI :)
116117

118+
### How does it work
119+
120+
Input:
121+
122+
```vue
123+
<template>
124+
<h1>hello</h1>
125+
</template>
126+
127+
<script>
128+
import { css } from 'styled-vue'
129+
130+
export default {
131+
style: css`
132+
h1 {
133+
color: ${vm => vm.color};
134+
width: ${200 + 1}px;
135+
}
136+
`
137+
}
138+
</script>
139+
```
140+
141+
Output:
142+
143+
```vue
144+
<template>
145+
<h1 :style="$options.style(this)">hello</h1>
146+
</template>
147+
148+
<script>
149+
export default {
150+
style: function(vm) {
151+
var v0 = vm => vm.color
152+
var v1 = 200 + 1
153+
return {
154+
'--v0': v0(vm),
155+
'--v1': v1 + 'px'
156+
}
157+
}
158+
}
159+
</script>
160+
161+
<style scoped>
162+
h1 {
163+
color: var(--v0);
164+
width: var(--v1);
165+
}
166+
</style>
167+
```
168+
169+
What a trick... It uses [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables) for dynamic styles, that's why this feature is not supported in IE.
170+
117171
### CSS Preprocessors
118172

119173
```js
120-
import { css, less, sass, scss, stylus } from 'styled-vue'
174+
import { less, sass, scss, stylus } from 'styled-vue'
121175
```
122176

123177
Just use corresponding exports from `styled-vue`.
124178

125-
The CSS will be passed to `vue-loader`, so it really just works like `<style scoped>`.
179+
The CSS will be passed to `vue-loader` and parsed by PostCSS if a `postcss.config.js` exists in your project, so it really just works like `<style scoped>`.
126180

127181
### Global Styles
128182

0 commit comments

Comments
 (0)