FontAmount.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <span :style="{ fontSize: amount_font_size + 'px' }">{{ amount }}</span>
  3. </template>
  4. <script>
  5. export default {
  6. props: {
  7. amount: {
  8. type: String,
  9. default: ''
  10. },
  11. width: {
  12. type: Number,
  13. default: 360
  14. },
  15. fontSize: {
  16. type: Number,
  17. default: 56
  18. },
  19. },
  20. data() {
  21. return {
  22. amount_font_size: 60,
  23. }
  24. },
  25. watch: {
  26. amount(newV) {
  27. if (newV) {
  28. this.setFontSize()
  29. }
  30. },
  31. width(newV) {
  32. if (newV) {
  33. this.setFontSize()
  34. }
  35. },
  36. fontSize(newV) {
  37. if (newV) {
  38. this.setFontSize()
  39. }
  40. },
  41. },
  42. mounted() {
  43. this.setFontSize()
  44. },
  45. methods: {
  46. setFontSize() {
  47. let _num = parseInt(this.width / this.amount.length);
  48. this.amount_font_size = _num < this.fontSize ? _num : this.fontSize;
  49. }
  50. }
  51. }
  52. </script>
  53. <style lang="scss" scoped>
  54. </style>