Item.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <div class="count-item">
  3. <span class="title">{{ title }}</span>
  4. <span v-for="num in nums" :class="num == ',' ? 'separator' : 'num'">{{ num }}</span>
  5. </div>
  6. </template>
  7. <script>
  8. export default {
  9. name: 'count-item',
  10. props: {
  11. value: {
  12. default: 0,
  13. type: Number
  14. },
  15. title: {
  16. type: String
  17. }
  18. },
  19. methods: {
  20. formatNumber (num) {
  21. let re = /(\d+)(\d{3})/
  22. num = (Array(10 - String(num).length).join(0) + num)
  23. while (re.test(num)) {
  24. num = num.replace(re, '$1,$2')
  25. }
  26. return num.split('')
  27. }
  28. },
  29. computed: {
  30. nums () {
  31. return this.formatNumber(this.value)
  32. }
  33. }
  34. }
  35. </script>
  36. <style lang="scss" scoped>
  37. @import '~assets/scss/variables';
  38. .count-item {
  39. text-align: center;
  40. line-height: 20px;
  41. .title {
  42. display: inline-block;
  43. width: 60px;
  44. float: left;
  45. font-weight: bold;
  46. }
  47. .separator, .num {
  48. display: inline-block;
  49. }
  50. .separator {
  51. font-size: 12px;
  52. color: $primary;
  53. margin: 0 5px 0 -2px;
  54. }
  55. .num {
  56. background: $primary;
  57. width: 15px;
  58. height: 20px;
  59. margin-right: 10px;
  60. text-align: center;
  61. color: $white;
  62. font-weight: bold;
  63. }
  64. }
  65. </style>