FontZoom.vue 917 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <!-- 组件确定最大宽度时 可等比缩放组件 -->
  2. <template>
  3. <span class="zoom-wrap" 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. },
  15. data() {
  16. return {
  17. zoom: 1,
  18. }
  19. },
  20. mounted() {
  21. this.setFontZoom()
  22. },
  23. methods: {
  24. setFontZoom() {
  25. this.$nextTick(() => {
  26. let offsetWidth = this.$refs.zoomDom.offsetWidth;
  27. console.log(this.$refs)
  28. console.log('refs', this.$refs.zoomDom.offsetWidth)
  29. this.zoom = offsetWidth > this.width ? +this.width / offsetWidth : 1
  30. })
  31. }
  32. }
  33. }
  34. </script>
  35. <style lang="scss" scoped>
  36. .zoom-wrap {
  37. color: #fff;
  38. display: flex;
  39. align-items: center;
  40. justify-content: center;
  41. white-space: nowrap;
  42. }
  43. </style>