File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff 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">
122126import { styled } from '@vvibe/vue-styled-components';
123127
124128const 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
Original file line number Diff line number Diff 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">
120122import { styled } from '@vvibe/vue-styled-components';
121123
122124const 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
You can’t perform that action at this time.
0 commit comments