SlideBackground.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <div
  3. class="slide-background"
  4. :style="backgroundStyle"
  5. >
  6. <template v-if="isShowGridLines">
  7. <GridLines />
  8. <GridLines :gridSize="100" gridColor="rgba(100, 100, 100, 0.3)" />
  9. </template>
  10. </div>
  11. </template>
  12. <script>
  13. import { computed, defineComponent } from 'vue'
  14. import GridLines from './GridLines'
  15. export default defineComponent({
  16. name: 'slide-background',
  17. components: {
  18. GridLines,
  19. },
  20. props: {
  21. background: {
  22. type: Array,
  23. },
  24. isShowGridLines: {
  25. type: Boolean,
  26. default: false,
  27. },
  28. },
  29. setup(props) {
  30. const backgroundStyle = computed(() => {
  31. if(!props.background) return { backgroundColor: '#fff' }
  32. const [type, value] = props.background
  33. if(type === 'solid') return { backgroundColor: value }
  34. else if(type === 'image') return { backgroundImage: `url(${value}` }
  35. return { backgroundColor: '#fff' }
  36. })
  37. return {
  38. backgroundStyle,
  39. }
  40. },
  41. })
  42. </script>
  43. <style lang="scss" scoped>
  44. .slide-background {
  45. width: 100%;
  46. height: 100%;
  47. background-position: center;
  48. background-size: cover;
  49. position: absolute;
  50. }
  51. </style>