index.vue 1017 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template>
  2. <div class="col-default" :style="styles">
  3. <slot></slot>
  4. </div>
  5. </template>
  6. <script>
  7. import {computed, inject, ref} from 'vue-demi'
  8. export default {
  9. name: 'm-col',
  10. props: {
  11. span: {
  12. type: Number,
  13. default: 24
  14. },
  15. offset: {
  16. type: Number,
  17. default: 0
  18. }
  19. },
  20. setup(props) {
  21. const widthRef = ref(props.span<=24?props.span%1==0?(100/24)*props.span+'%':'':'')
  22. const offsetRef = ref(props.offset<=24?props.offset%1==0?(100/24)*props.offset+'%':'':'')
  23. const gutter = inject('gutter')
  24. const styles = computed(() => {
  25. return {
  26. paddingLeft: gutter.value ? gutter.value / 2 + 'px' : '',
  27. paddingRight: gutter.value ? gutter.value / 2 + 'px' : ''
  28. }
  29. })
  30. return {
  31. widthRef,
  32. offsetRef,
  33. styles
  34. }
  35. }
  36. }
  37. </script>
  38. <style lang="scss" scoped>
  39. .col-default{
  40. max-width:v-bind(widthRef);
  41. flex: 0 0 v-bind(widthRef);
  42. float: left;
  43. margin-left:v-bind(offsetRef);
  44. box-sizing: border-box;
  45. }
  46. </style>