cl-divider.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <view class="cl-divider">
  3. <view class="cl-divider__line" :style="{ background: lineColor, width }"></view>
  4. <view
  5. class="cl-divider__text"
  6. :style="{
  7. backgroundColor
  8. }"
  9. >
  10. <slot></slot>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. import { isArray } from "../../utils";
  16. /**
  17. * divider 分隔符
  18. * @description 分割符组件,区隔内容的分割线
  19. * @tutorial https://docs.cool-js.com/uni/components/basic/divider.html
  20. * @property {String} backgroundColor 背景颜色,默认#fff
  21. * @property {String, Array} color 线条颜色,Array 下当渐变色处理
  22. * @property {String} width 线条宽度
  23. * @example <cl-divider>默认</cl-divider>
  24. */
  25. export default {
  26. name: "cl-divider",
  27. props: {
  28. backgroundColor: {
  29. type: String,
  30. default: "#fff"
  31. },
  32. color: {
  33. type: [String, Array],
  34. default: "#dcdfe6"
  35. },
  36. width: {
  37. type: String,
  38. default: "100%"
  39. }
  40. },
  41. computed: {
  42. lineColor() {
  43. if (isArray(this.color)) {
  44. const [a, b] = this.color || [];
  45. return `linear-gradient(to right, ${a}, ${b}, ${b}, ${a})`;
  46. } else {
  47. return this.color;
  48. }
  49. }
  50. }
  51. };
  52. </script>