demo-title.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <view class="demo-title">
  3. <view>
  4. <view v-if="type === 'first'" class="main_title">
  5. <view v-if="leftIcon" class="main_title__icon main_title__icon--left" :class="[`tn-icon-${leftIcon}`]"></view>
  6. <view class="main_title__content">{{ title }}</view>
  7. <view v-if="rightIcon" class="main_title__icon main_title__icon--right" :class="[`tn-icon-${rightIcon}`]"></view>
  8. </view>
  9. <view v-if="type === 'second'" class="second_title">
  10. <view class="second_title__content">{{ title }}</view>
  11. </view>
  12. </view>
  13. <view class="content" :class="[{
  14. 'content--padding': contentPadding
  15. }]">
  16. <slot></slot>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. name: 'demo-title',
  23. options: {
  24. // 在微信小程序中将组件节点渲染为虚拟节点,更加接近Vue组件的表现(不会出现shadow节点下再去创建元素)
  25. virtualHost: true
  26. },
  27. props: {
  28. // 标题类型
  29. type: {
  30. type: String,
  31. default: 'first'
  32. },
  33. // 标题
  34. title: {
  35. type: String,
  36. default: ''
  37. },
  38. // 左图标
  39. leftIcon: {
  40. type: String,
  41. default: 'star'
  42. },
  43. // 右图标
  44. rightIcon: {
  45. type: String,
  46. default: 'star'
  47. },
  48. // 内容容器是否有两边边距
  49. contentPadding: {
  50. type: Boolean,
  51. default: true
  52. }
  53. }
  54. }
  55. </script>
  56. <style lang="scss" scoped>
  57. .main_title {
  58. display: flex;
  59. align-items: center;
  60. justify-content: center;
  61. margin-top: 50rpx;
  62. font-size: 36rpx;
  63. font-weight: bold;
  64. &__content {
  65. padding: 0 18rpx;
  66. }
  67. &__icon {
  68. font-size: 34rpx;
  69. }
  70. }
  71. .second_title {
  72. margin: 24rpx 0;
  73. margin-left: 30rpx;
  74. &__content {
  75. font-size: 32rpx;
  76. font-weight: bold;
  77. }
  78. }
  79. .content {
  80. margin-top: 30rpx;
  81. &--padding {
  82. margin-left: 30rpx;
  83. margin-right: 30rpx;
  84. }
  85. }
  86. </style>