Skip to content

Commit 79a7120

Browse files
committed
docs(readme): amend incorrect intro for passing props
1 parent aa03f6e commit 79a7120

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,16 @@ const StyledDiv = styled.div.attrs({
117117

118118
### Control Dynamic Style by Props
119119

120+
You must define the props in the `styled` function if you want to use them in the style. Because Vue components
121+
require explicit props declaration so that Vue knows what external props passed to the component should be treated as
122+
fallthrough attributes.(see [Props Declaration](https://vuejs.org/guide/components/props.html#props-declaration))
123+
120124
```vue
121125
<script setup lang="ts">
122126
import { styled } from '@vvibe/vue-styled-components';
123127
124128
const StyledDiv = styled('div', {
125-
color: '#fff'
129+
color: String
126130
})`
127131
width: 100px;
128132
height: 100px;
@@ -132,7 +136,7 @@ const StyledDiv = styled('div', {
132136
</script>
133137
134138
<template>
135-
<StyledDiv>Styled Div</StyledDiv>
139+
<StyledDiv color="red">Styled Div</StyledDiv>
136140
</template>
137141
```
138142

README.zh_CN.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,14 @@ const StyledDiv = styled.div.attrs({
115115

116116
### 通过 Props 动态控制样式
117117

118+
如果要在样式中传递 props,则必须在 styled 函数中定义这些属性。因为 Vue 组件需要显式声明 props,以便 Vue 知道应如何处理传递给组件的外部 props(请参阅 [Props Declaration](https://vuejs.org/guide/components/props.html#props-declaration)
119+
118120
```vue
119121
<script setup lang="ts">
120122
import { styled } from '@vvibe/vue-styled-components';
121123
122124
const StyledDiv = styled('div', {
123-
color: '#fff'
125+
color: String
124126
})`
125127
width: 100px;
126128
height: 100px;
@@ -130,7 +132,7 @@ const StyledDiv = styled('div', {
130132
</script>
131133
132134
<template>
133-
<StyledDiv>Styled Div</StyledDiv>
135+
<StyledDiv color="red">Styled Div</StyledDiv>
134136
</template>
135137
```
136138

0 commit comments

Comments
 (0)