wd-col.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <view :class="['wd-col', span && 'wd-col__' + span, offset && 'wd-col__offset-' + offset, customClass]" :style="rootStyle">
  3. <!-- 每一列 -->
  4. <slot />
  5. </view>
  6. </template>
  7. <script lang="ts">
  8. export default {
  9. name: 'wd-col',
  10. options: {
  11. addGlobalClass: true,
  12. virtualHost: true,
  13. styleIsolation: 'shared'
  14. }
  15. }
  16. </script>
  17. <script lang="ts" setup>
  18. import { computed, watch } from 'vue'
  19. import { useParent } from '../composables/useParent'
  20. import { ROW_KEY } from '../wd-row/types'
  21. import { colProps } from './types'
  22. import { isDef } from '../common/util'
  23. const props = defineProps(colProps)
  24. const { parent: row } = useParent(ROW_KEY)
  25. const rootStyle = computed(() => {
  26. const gutter = isDef(row) ? row.props.gutter || 0 : 0
  27. const padding = `${gutter / 2}px`
  28. const style = gutter > 0 ? `padding-left: ${padding}; padding-right: ${padding};background-clip: content-box;` : ''
  29. return `${style}${props.customStyle}`
  30. })
  31. watch([() => props.span, () => props.offset], () => {
  32. check()
  33. })
  34. function check() {
  35. const { span, offset } = props
  36. if (span < 0 || offset < 0) {
  37. console.error('[wot-design] warning(wd-col): attribute span/offset must be greater than or equal to 0')
  38. }
  39. }
  40. </script>
  41. <style lang="scss" scoped>
  42. @import './index.scss';
  43. </style>