wxc-flex

    常见布局 - 水平垂直居中

    1. <wxc-flex class="wrap" main="center" cross="center">
    2. <view class="item"></view>
    3. <view class="item"></view>
    4. </wxc-flex>
    5. <view class="layout-code">
    6. <wxc-flex <view class="layout-code__point">main="center" cross="center"</view>>...</wxc-flex>
    7. </view>
    8. </template>
    9. <script>
    10. export default {
    11. config: {
    12. usingComponents: {
    13. 'wxc-flex': '@minui/wxc-flex'
    14. }
    15. },
    16. data: {},
    17. methods: {}
    18. }
    19. </script>
    20. <style>
    21. .wrap {
    22. display: block;
    23. height: 300rpx;
    24. padding: 10rpx;
    25. background: #696969;
    26. }
    27. .item {
    28. min-width: 100rpx;
    29. min-height: 100rpx;
    30. }
    31. .item:nth-of-type(odd) {
    32. background: #afdde3
    33. }
    34. .item:nth-of-type(2n) {
    35. background: #f397b2
    36. }
    37. .layout-code {
    38. padding: 15rpx;
    39. background: #222222;
    40. color: #FFFFFF;
    41. font-size: 20rpx;
    42. font-family: Monaco;
    43. }
    44. .layout-code__point {
    45. display: inline-block;
    46. padding: 0 5rpx;
    47. background: #444444;
    48. }
    49. </style>

    交叉轴排列

    项目在交叉轴上如何对齐

    flex flex - 图2

    主轴方向

    1. <template>
    2. <wxc-flex class="wrap" dir="{{dir}}">
    3. <view class="item">栏 1</view>
    4. <view class="item">栏 2</view>
    5. </wxc-flex>
    6. <view class="layout-code">
    7. <wxc-flex <view class="layout-code__point">dir="{{dir}}"</view>>...</wxc-flex>
    8. </view>
    9. <view class="setting-button" bindtap="setDirToLeft">水平正序(默认)</view>
    10. <view class="setting-button" bindtap="setDirToRight">水平倒序</view>
    11. <view class="setting-button" bindtap="setDirToBottom">垂直倒序</view>
    12. </template>
    13. <script>
    14. export default {
    15. config: {
    16. usingComponents: {
    17. 'wxc-flex': '@minui/wxc-flex'
    18. }
    19. },
    20. data: {
    21. dir: 'left'
    22. },
    23. /** note: 在 wxp 文件或者页面文件中请去掉 methods 包装 */
    24. methods: {
    25. setDirToLeft: function () {
    26. this.setData({
    27. dir: 'left'
    28. })
    29. },
    30. setDirToRight: function () {
    31. this.setData({
    32. dir: 'right'
    33. })
    34. },
    35. setDirToTop: function () {
    36. this.setData({
    37. dir: 'top'
    38. })
    39. },
    40. setDirToBottom: function () {
    41. this.setData({
    42. dir: 'bottom'
    43. })
    44. }
    45. }
    46. }
    47. </script>
    48. <style>
    49. .wrap {
    50. display: block;
    51. padding: 10rpx;
    52. background: #696969;
    53. }
    54. .item {
    55. min-width: 100rpx;
    56. min-height: 100rpx;
    57. font-size: 22rpx;
    58. text-align: center;
    59. }
    60. .item:nth-of-type(odd) {
    61. line-height: 30rpx;
    62. background: #afdde3
    63. }
    64. .item:nth-of-type(2n) {
    65. line-height: 50rpx;
    66. background: #f397b2
    67. }
    68. .setting-button {
    69. display: inline-block;
    70. line-height: 50rpx;
    71. margin: 20rpx 10rpx 0 0;
    72. padding: 2rpx 20rpx;
    73. border-radius: 6rpx;
    74. color: #ffffff;
    75. font-size: 18rpx;
    76. text-align: center;
    77. }
    78. .layout-code {
    79. padding: 15rpx;
    80. background: #222222;
    81. color: #FFFFFF;
    82. font-size: 20rpx;
    83. font-family: Monaco;
    84. }
    85. .layout-code__point {
    86. display: inline-block;
    87. padding: 0 5rpx;
    88. background: #444444;
    89. }
    90. </style>

    常见布局 - 定宽+弹性宽度

    flex flex - 图4

    常见布局 - 列表

    1. <template>
    2. <wxc-flex class="wrap" cross="top" wrap="wrap">
    3. <view class="item"></view>
    4. <view class="item"></view>
    5. <view class="item"></view>
    6. <view class="item"></view>
    7. <view class="item"></view>
    8. </wxc-flex>
    9. </template>
    10. <script>
    11. export default {
    12. config: {
    13. usingComponents: {
    14. 'wxc-flex': '@minui/wxc-flex'
    15. }
    16. },
    17. data: {},
    18. methods: {}
    19. }
    20. </script>
    21. <style>
    22. .wrap {
    23. display: block;
    24. padding: 2%;
    25. background: #696969;
    26. }
    27. .item {
    28. width: 47%;
    29. height: 348rpx;
    30. margin: 1.5%;
    31. flex-grow: 0;
    32. }
    33. .item:nth-of-type(odd) {
    34. background: #afdde3
    35. }
    36. .item:nth-of-type(2n) {
    37. background: #f397b2
    38. }
    39. </style>

    项目在主轴上的对齐方式

    flex flex - 图6

    换行选项

    如果一条轴线排不下,如何换行

    <template>
      <wxc-flex class="wrap" wrap="{{wrap}}">
        <view class="item">栏 1</view>
        <view class="item">栏 2</view>
        <view class="item">栏 3</view>
        <view class="item">栏 4</view>
        <view class="item">栏 5</view>
        <view class="item">栏 6</view>
        <view class="item">栏 7</view>
        <view class="item">栏 8</view>
        <view class="item">栏 9</view>
        <view class="item">栏 10</view>
        <view class="item">栏 11</view>
        <view class="item">栏 12</view>
      </wxc-flex>
    
      <view class="layout-code">
        <wxc-flex <view class="layout-code__point">wrap="{{wrap}}"</view>>...</wxc-flex>
      </view>
    
      <view class="setting-button" bindtap="setWrapToNowrap">不换行(默认)</view>
      <view class="setting-button" bindtap="setWrapToWrap">正序换行</view>
      <view class="setting-button" bindtap="setWrapToReverse">倒序换行</view>
    </template>
    
    <script>
    export default {
      config: {
        usingComponents: {
          'wxc-flex': '@minui/wxc-flex'
        }
      },
      data: {
        wrap: 'nowrap'
      },
      /** note: 在 wxp 文件或者页面文件中请去掉 methods 包装 */
      methods: {
        setWrapToNowrap: function () {
          this.setData({
            wrap: 'nowrap'
          })
        },
        setWrapToWrap: function () {
          this.setData({
            wrap: 'wrap'
          })
        },
        setWrapToReverse: function () {
          this.setData({
            wrap: 'reverse'
          })
        }
      }
    }
    </script>
    
    <style>
      .wrap {
        display: block;
        padding: 10rpx;
        background: #696969;
      }
      .item {
        min-width: 20%;
        min-height: 100rpx;
        font-size: 22rpx;
        text-align: center;
      }
      .item:nth-of-type(odd) {
        line-height: 30rpx;
        background: #afdde3
      }
      .item:nth-of-type(2n) {
        line-height: 50rpx;
        background: #f397b2
      }
    
      .setting-button {
        display: inline-block;
        line-height: 50rpx;
        margin: 20rpx 10rpx 0 0;
        padding: 2rpx 20rpx;
        border-radius: 6rpx;
        background: #31b0d5;
        color: #ffffff;
        font-size: 18rpx;
        text-align: center;
      }
    
      .layout-code {
        padding: 15rpx;
        background: #222222;
        color: #FFFFFF;
        font-size: 20rpx;
        font-family: Monaco;
      }
      .layout-code__point {
        display: inline-block;
        padding: 0 5rpx;
        background: #444444;
      }
    </style>
    

    Flex【props】

    地址
    flex 组件文档 https://meili.github.io/min/docs/minui/index.html#flex
    flex 组件源码
    MinUI 组件库 https://github.com/meili/minui

    flex

    v1.0.3(2018.6.5)

    • 增加点击事件。

    v1.0.2(2017.11.02)

    • update .npmignore

    v1.0.1(2017.10.24)