Skip to content

Commit

Permalink
fix(theme): incorrect <CardGrid> render, close #147
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo committed Aug 22, 2024
1 parent 06287ca commit a7c40e0
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions theme/src/client/components/global/VPCardGrid.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed } from 'vue'
import { computed, onMounted, ref, toValue, watch } from 'vue'
import { useMediaQuery } from '@vueuse/core'
const props = defineProps<{
Expand All @@ -8,34 +8,39 @@ const props = defineProps<{
const md = useMediaQuery('(min-width: 768px)')
const lg = useMediaQuery('(min-width: 960px)')
const repeat = ref(1)
const cols = computed(() => {
function resolveCols() {
const reset = { sm: 1, md: 2, lg: 2 }
if (!props.cols)
return reset
if (typeof props.cols === 'number' || typeof props.cols === 'string') {
const cols = Number(props.cols)
return { sm: cols, md: cols, lg: cols }
}
return { ...reset, ...props.cols }
})
return { ...reset, ...toValue(props.cols) }
}
const repeat = computed(() => {
function getRepeat() {
const cols = resolveCols()
if (lg.value)
return cols.value.lg
else if (md.value)
return cols.value.md
else
return cols.value.sm
return cols.lg
if (md.value)
return cols.md
return cols.sm
}
watch([md, lg], () => {
repeat.value = getRepeat()
})
onMounted(() => {
repeat.value = getRepeat()
})
</script>

<template>
<div
class="vp-card-grid" :class="[`cols-${repeat}`]" :style="{
gridTemplateColumns: `repeat(${repeat}, 1fr)`,
}"
>
<div class="vp-card-grid" :class="[`cols-${repeat}`]" :style="{ gridTemplateColumns: `repeat(${repeat}, 1fr)` }">
<slot />
</div>
</template>
Expand Down

0 comments on commit a7c40e0

Please sign in to comment.