File tree Expand file tree Collapse file tree 2 files changed +74
-2
lines changed
Expand file tree Collapse file tree 2 files changed +74
-2
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ outline: deep
77You can pass props to the styled component, similar to Vue components. For instance, you can pass a placeholder to the
88styled input.
99
10+ ## Basic
11+
1012::: demo
1113
1214``` vue
@@ -41,8 +43,42 @@ the input.
4143
4244::: tip NOTE
4345
44- You must define the props in the ` styled ` function if you want to use them in the style. Because Vue components
46+ You need define the props in the ` styled ` function if you want to use them directly in the style. Because Vue components
4547require explicit props declaration so that Vue knows what external props passed to the component should be treated as
4648fallthrough attributes.(see [ Props Declaration] ( https://vuejs.org/guide/components/props.html#props-declaration ) )
4749
4850:::
51+
52+ ## New way to pass props
53+
54+ From ` v1.7.0 ` , you can use the ` props ` option to pass props to the styled component.
55+
56+ ::: demo
57+ ``` vue
58+ <script setup lang="ts">
59+ import { ref } from 'vue'
60+ import { styled } from '@vue-styled-components/core'
61+
62+ const borderColor = ref('darkred')
63+ const StyledInput = styled.input`
64+ width: 100%;
65+ height: 40px;
66+ padding: 4px 8px;
67+ border: 1px solid ${(props) => props.borderColor};
68+ border-radius: 8px;
69+ `
70+
71+ const input = () => (borderColor.value = 'forestgreen')
72+ const focus = () => (borderColor.value = 'skyblue ')
73+ const blur = () => (borderColor.value = 'darkred')
74+ </script>
75+
76+ <template>
77+ <StyledInput
78+ placeholder="Type something"
79+ :props="{ borderColor }"
80+ @input="input"
81+ @focus="focus"
82+ @blur="blur"
83+ />
84+ </template>
Original file line number Diff line number Diff line change @@ -39,6 +39,42 @@ const blur = () => (borderColor.value = 'darkred')
3939
4040::: tip 注意
4141
42- 如果要在样式中使用属性,则必须在 styled 函数中定义这些属性。因为 Vue 组件需要显式声明 props,以便 Vue 知道应如何处理传递给组件的外部 props(请参阅 [ Props Declaration] ( https://vuejs.org/guide/components/props.html#props-declaration ) )
42+ 如果要在样式中使用属性,则需要在 styled 函数中定义这些属性。因为 Vue 组件需要显式声明 props,以便 Vue 知道应如何处理传递给组件的外部 props(请参阅 [ Props Declaration] ( https://vuejs.org/guide/components/props.html#props-declaration ) )
4343
4444:::
45+
46+
47+ ## 新的 props 选项
48+
49+ 从 ` v1.7.0 ` 开始,您可以使用 ` props ` 选项将属性传递给样式化的组件。
50+
51+ ::: demo
52+ ``` vue
53+ <script setup lang="ts">
54+ import { ref } from 'vue'
55+ import { styled } from '@vue-styled-components/core'
56+
57+ const borderColor = ref('darkred')
58+ const StyledInput = styled.input`
59+ width: 100%;
60+ height: 40px;
61+ padding: 4px 8px;
62+ border: 1px solid ${(props) => props.borderColor};
63+ border-radius: 8px;
64+ `
65+
66+ const input = () => (borderColor.value = 'forestgreen')
67+ const focus = () => (borderColor.value = 'skyblue ')
68+ const blur = () => (borderColor.value = 'darkred')
69+ </script>
70+
71+ <template>
72+ <StyledInput
73+ placeholder="Type something"
74+ :props="{ borderColor }"
75+ @input="input"
76+ @focus="focus"
77+ @blur="blur"
78+ />
79+ </template>
80+
You can’t perform that action at this time.
0 commit comments