文档管理中心
指南快应用专题框架自定义组件章节标题组件

章节标题组件

简介

章节标题(title)组件通常用于记录页面标题,例如商品标题、新闻标题等。章节标题一般具有如下特点:

  • 可设置章节标题的标题类型
  • 可设置章节标题的对齐方式
  • 可设置章节标题的内容及字体颜色

效果图如下:

基本布局代码如下:

收起
自动换行
深色代码主题
复制
  1. <import name="title" src="./Title/title1.ux"></import>
  2. <template>
  3. <!-- Only one root node is allowed in template. -->
  4. <div class="container">
  5. <text>章节标题通常用于记录页面标题,例如商品标题、新闻标题等</text>
  6. <div class="item-content">
  7. <text class="section">基本用法</text>
  8. <div class="example-body">
  9. <title type="h1" title="h1 一级标题 设置左对齐" color="black" align="left"> </title>
  10. <title type="h2" title="h2 二级标题 设置标题类型" color="black" align="left"> </title>
  11. <title type="h3" title="h3 三级标题 设置居中" color="black" align="center"> </title>
  12. <title type="h4" title="h4 四级标题 设置右对齐" color="black" align="right"> </title>
  13. <title type="h5" title="h5 五级标题 改变颜色" color="#7db9f7" align="left"> </title>
  14. </div>
  15. </div>
  16. </div>
  17. </template>

开发指引

自定义子组件

  1. 定义布局样式。

    章节标题组件由div和text组件构成。

    收起
    自动换行
    深色代码主题
    复制
    1. <template>
    2. <div class="box" style="align-items:{{textAlign}}">
    3. <text class="{{type}}" style="color: {{color}}">{{title}}</text>
    4. </div>
    5. </template>
  2. 规划属性。

    支持的属性:

    展开

    属性

    类型

    默认值

    描述

    type

    String

    -

    标题类型,可选值:h1、h2、h3、h4、h5,章节标题字体会比正常字长字体粗。

    title

    String

    -

    章节标题内容。

    align

    String

    left

    对齐方式,可选值:

    • left:左对齐
    • center:居中
    • right:右对齐

    color

    String

    #333333

    字体颜色。

父子组件通信

子组件的props中定义相关属性值,父组件引用时传入属性值,子组件通过 this.xxx 获取值并进行处理。

收起
自动换行
深色代码主题
复制
  1. props: {
  2. type: {
  3. type: String,
  4. default: ''
  5. },
  6. title: {
  7. type: String,
  8. default: ''
  9. },
  10. align: {
  11. type: String,
  12. default: 'left'
  13. },
  14. color: {
  15. type: String,
  16. default: '#333333'
  17. },
  18. },

计算style样式

使用计算属性computed方法,通过props属性动态计算样式,返回给组件使用。

收起
自动换行
深色代码主题
复制
  1. computed: {
  2. textAlign() {
  3. let align = 'center';
  4. switch (this.align) {
  5. case 'left':
  6. align = 'flex-start'
  7. break;
  8. case 'center':
  9. align = 'center'
  10. break;
  11. case 'right':
  12. align = 'flex-end'
  13. break;
  14. }
  15. return align
  16. }
  17. },

示例代码

章节标题title.ux代码:

收起
自动换行
深色代码主题
复制
  1. <template>
  2. <div class="box" style="align-items:{{textAlign}}">
  3. <text class="{{type}}" style="color: {{color}}">{{title}}</text>
  4. </div>
  5. </template>
  6. <style lang="less" >
  7. .box {
  8. flex-direction: column;
  9. justify-content: center;
  10. }
  11. .h1 {
  12. font-size: 30px;
  13. color: #333;
  14. font-weight: bold;
  15. }
  16. .h2 {
  17. font-size: 28px;
  18. color: #333;
  19. font-weight: bold;
  20. }
  21. .h3 {
  22. font-size: 26px;
  23. color: #333;
  24. font-weight: bold;
  25. /* font-weight: 400; */
  26. }
  27. .h4 {
  28. font-size: 24px;
  29. color: #333;
  30. font-weight: bold;
  31. /* font-weight: 300; */
  32. }
  33. .h5 {
  34. font-size: 22px;
  35. color: #333;
  36. font-weight: bold;
  37. /* font-weight: 200; */
  38. }
  39. </style>
  40. <script>
  41. export default {
  42. props: {
  43. type: {
  44. type: String,
  45. default: ''
  46. },
  47. title: {
  48. type: String,
  49. default: ''
  50. },
  51. align: {
  52. type: String,
  53. default: 'left'
  54. },
  55. color: {
  56. type: String,
  57. default: '#333333'
  58. },
  59. },
  60. computed: {
  61. textAlign() {
  62. let align = 'center';
  63. switch (this.align) {
  64. case 'left':
  65. align = 'flex-start'
  66. break;
  67. case 'center':
  68. align = 'center'
  69. break;
  70. case 'right':
  71. align = 'flex-end'
  72. break;
  73. }
  74. return align
  75. }
  76. },
  77. }
  78. </script>

页面hello.ux代码:

收起
自动换行
深色代码主题
复制
  1. <import name="title" src="./Title/title1.ux"></import>
  2. <template>
  3. <!-- Only one root node is allowed in template. -->
  4. <div class="container">
  5. <text>章节标题通常用于记录页面标题,例如商品标题、新闻标题等</text>
  6. <div class="item-content">
  7. <text class="section">不同类型:</text>
  8. <div class="example-body">
  9. <title type="h1" title="h1 一级标题" color="black" align="left"> </title>
  10. <title type="h2" title="h2 二级标题" color="black" align="left"> </title>
  11. <title type="h3" title="h3 三级标题" color="black" align="left"> </title>
  12. <title type="h4" title="h4 四级标题" color="black" align="left"> </title>
  13. <title type="h5" title="h5 五级标题" color="black" align="left"> </title>
  14. </div>
  15. </div>
  16. <div class="item-content">
  17. <text class="section">对齐方式:</text>
  18. <div class="example-body">
  19. <title type="h1" title="h1 左对齐" color="#027fff" align="left"> </title>
  20. <title type="h2" title="h2 居中" color="#027fff" align="center"> </title>
  21. <title type="h3" title="h3 右对齐" color="#027fff" align="right"> </title>
  22. <title type="h4" title="h4 居中" color="#027fff" align="center"> </title>
  23. <title type="h5" title="h5 左对齐" color="#027fff" align="left"> </title>
  24. </div>
  25. </div>
  26. <div class="item-content">
  27. <text class="section">改变颜色:</text>
  28. <div class="example-body">
  29. <title type="h1" title="h1 一级标题" color="#027fff" align="left"> </title>
  30. <title type="h2" title="h2 二级标题" color="#2490ff" align="left"> </title>
  31. <title type="h3" title="h3 三级标题" color="#439ffc" align="left"> </title>
  32. <title type="h4" title="h4 四级标题" color="#60adfb" align="left"> </title>
  33. <title type="h5" title="h5 五级标题" color="#7db9f7" align="left"> </title>
  34. </div>
  35. </div>
  36. <div class="item-content">
  37. <text class="section">组合示例:</text>
  38. <div class="example-body">
  39. <title class="box-head" type="h1" title="章节标题" color="#027fff" align="center"> </title>
  40. <title class="box" type="h3" title="1 简介" color="#2490ff" align="left"> </title>
  41. <div>
  42. <text class="text">章节标题通常用于记录页面标题,例如商品标题、新闻标题等。章节标题一般具有如下特点:</text>
  43. </div>
  44. <title type="h5" color="#666" title="- 可设置章节标题的标题类型,章节标题字体会比正常字长字体粗"></title>
  45. <title type="h5" color="#666" title="- 可设置章节标题的对齐方式"></title>
  46. <title type="h5" color="#666" title="- 可设置章节标题的内容及字体颜色"></title>
  47. </div>
  48. <div class="example-body">
  49. <title class="box" type="h3" title="2 开发指引" color="#2490ff" align="left"> </title>
  50. <title class="box" type="h4" title="2.1 自定义子组件" align="left"></title>
  51. <div>
  52. <text class="text">1.定义布局样式。 </text>
  53. </div>
  54. <div>
  55. <text class="text">2.规划属性和支持的事件。</text>
  56. </div>
  57. <title class="box" type="h4" title="2.2 父子组件通信" align="left"></title>
  58. <div>
  59. <text class="text">子组件的props中定义参数。</text>
  60. </div>
  61. <title class="box" type="h4" title="2.3 计算style样式" align="left"></title>
  62. <div>
  63. <text class="text">使用计算属性computed方法,通过props属性动态计算数据和样式,返回给组件使用。</text>
  64. </div>
  65. </div>
  66. <div class="example-body">
  67. <title type="h2" title="示例代码" align="left"></title>
  68. </div>
  69. </div>
  70. </div>
  71. </template>
  72. <style>
  73. .container {
  74. flex-direction: column;
  75. }
  76. .section {
  77. font-size: 35px;
  78. padding: 10px;
  79. background-color: rgb(235, 233, 233);
  80. }
  81. .item-content {
  82. width: 100%;
  83. flex-direction: column;
  84. align-content: center;
  85. }
  86. .example-body {
  87. padding: 10px;
  88. flex-direction: column;
  89. }
  90. .text {
  91. font-size: 25px;
  92. line-height: 22px;
  93. color: #333;
  94. line-height: 45px
  95. }
  96. .box-head {
  97. height: 100px;
  98. }
  99. .box {
  100. height: 60px;
  101. }
  102. </style>
  103. <script>
  104. module.exports = {
  105. data() {
  106. },
  107. onInit() {
  108. this.$page.setTitleBar({text: '章节标题'})
  109. },
  110. }
  111. </script>
在 指南 中进行搜索
请输入您想要搜索的关键词