FontZoom.vue 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <!-- 组件确定最大宽度时 可等比缩放组件 -->
  2. <template>
  3. <span class="zoom-wrap" :class="{unColor: unColor}" ref="zoomDom" :style="{ zoom: zoom }">
  4. <slot></slot>
  5. </span>
  6. </template>
  7. <script>
  8. export default {
  9. props: {
  10. width: {
  11. type: String,
  12. default: '375'
  13. },
  14. unColor: {
  15. type: Boolean,
  16. default: false
  17. },
  18. },
  19. data() {
  20. return {
  21. zoom: 1,
  22. }
  23. },
  24. mounted() {
  25. this.setFontZoom()
  26. },
  27. methods: {
  28. setFontZoom() {
  29. this.$nextTick(() => {
  30. let offsetWidth = this.$refs.zoomDom.offsetWidth;
  31. console.log(this.$refs)
  32. console.log('refs', this.$refs.zoomDom.offsetWidth)
  33. this.zoom = offsetWidth > this.width ? +this.width / offsetWidth : 1
  34. })
  35. }
  36. }
  37. }
  38. </script>
  39. <style lang="scss" scoped>
  40. .zoom-wrap {
  41. color: #fff;
  42. display: flex;
  43. align-items: center;
  44. justify-content: center;
  45. white-space: nowrap;
  46. &.unColor {
  47. color: unset;
  48. }
  49. }
  50. </style>