领峰UI库,封装一些经常使用到的组件,自定义样式,模块化js函数,调用简单快速上手。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.3 KiB

  1. <template>
  2. <view :style="{'--color': color, 'display': 'inline-block'}">
  3. <block v-if="isPoint">
  4. <text class="price-one text-price">{{ showPrice(1) }}</text>
  5. <text class="price-two">.{{ showPrice(2) }}</text>
  6. </block>
  7. <block v-else>
  8. <text class="price-one text-price">{{ showPrice() }}</text>
  9. </block>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. props: {
  15. price: {
  16. type: [Number, String],
  17. default: ''
  18. },
  19. color: {
  20. type: String,
  21. default: '#FF0000'
  22. }
  23. },
  24. computed: {
  25. // 是否存在小数点
  26. isPoint(){
  27. let price = parseFloat(this.$props.price).toString();
  28. return price.indexOf('.') >= 0;
  29. },
  30. showPrice(){
  31. let price = parseFloat(this.$props.price).toString(); // 过滤价格出现.00的情况
  32. return function(type){
  33. let price_arr = price.split('.');
  34. if(type == 1){
  35. return price_arr[0];
  36. }else if(type == 2){
  37. return price_arr[1];
  38. }else{
  39. return price_arr[0];
  40. }
  41. }
  42. }
  43. }
  44. }
  45. </script>
  46. <style lang="scss" scoped="scoped">
  47. .price-one{
  48. font-size: 48rpx;
  49. font-weight: bold;
  50. color: var(--color);
  51. }
  52. .price-two{
  53. font-size: 28rpx;
  54. font-weight: bold;
  55. color: var(--color);
  56. }
  57. .text-price::before {
  58. content: "¥";
  59. font-size: 28rpx!important;
  60. margin-right: 4rpx;
  61. font-weight: bold;
  62. color: var(--color);
  63. }
  64. </style>