Skip to content

Commit

Permalink
fix: fix the bug of style-provider when update
Browse files Browse the repository at this point in the history
  • Loading branch information
BeADre committed Jun 23, 2021
1 parent 36dd315 commit 0640b4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
15 changes: 11 additions & 4 deletions packages/varlet-ui/src/style-provider/example/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</template>

<script>
import { onMounted, ref } from 'vue'
import Cell from '../../cell'
import StyleProvider from '../index'
Expand All @@ -16,10 +17,16 @@ export default {
[StyleProvider.name]: StyleProvider,
},
setup() {
const styles = {
cellFontSize: '30px',
cellBorderColor: 'red'
}
const styles = ref({})
onMounted(() => {
setTimeout(() => {
styles.value = {
cellFontSize: '30px',
cellBorderColor: 'red'
}
}, 1500)
})
return {
styles
Expand Down
14 changes: 8 additions & 6 deletions packages/varlet-ui/src/style-provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ export default defineComponent({
}
},
setup(props, { slots }) {
const styles: Record<string, string | number> = Object.entries(props.styleVars).reduce((styles, style) => {
const cssVar = `--${kebabCase(style[0])}`
styles[cssVar] = style[1] as string | number
return () => {
const styles: Record<string, string | number> = Object.entries(props.styleVars).reduce((styles, style) => {
const cssVar = `--${kebabCase(style[0])}`
styles[cssVar] = style[1] as string | number

return styles
}, {} as Record<string, string | number>)
return styles
}, {} as Record<string, string | number>)

return () => h('div', { style: styles }, slots.default?.())
return h('div', { style: styles }, slots.default?.())
}
}
})

0 comments on commit 0640b4e

Please sign in to comment.