view.uvue 9.2 KB
Newer Older
Y
init  
yurj26 已提交
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
    <!-- #endif -->
Y
init  
yurj26 已提交
5
    <view>
DCloud-WZF's avatar
DCloud-WZF 已提交
6 7 8 9 10 11 12 13 14 15
      <page-head title="view"></page-head>
      <view class="uni-padding-wrap uni-common-mt">
        <view>
          <text class="uni-hello-text">
            Flex是Flexible
            Box的缩写,意为“弹性布局”,用来为盒状模型提供最大的灵活性。当设置display:
            flex后,继续给view等容器组件设置flex-direction:
            row或column,就可以在该容器内按行或列排布子组件。uni-app推荐使用flex布局。因为flex布局有利于跨更多平台,尤其是采用原生渲染的平台。
          </text>
        </view>
Y
init  
yurj26 已提交
16

DCloud-WZF's avatar
DCloud-WZF 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
        <view class="uni-title uni-common-mt">
          <text class="uni-title-text"> flex-direction: row </text>
          <text class="uni-subtitle-text"> 横向布局 </text>
        </view>
        <view class="uni-flex uni-row">
          <view class="flex-item uni-bg-red"
            ><text style="color: #fff">A</text></view
          >
          <view class="flex-item uni-bg-green"
            ><text style="color: #fff">B</text></view
          >
          <view class="flex-item uni-bg-blue"
            ><text style="color: #fff">C</text></view
          >
        </view>
Y
init  
yurj26 已提交
32

DCloud-WZF's avatar
DCloud-WZF 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
        <view class="uni-title uni-common-mt">
          <text class="uni-title-text"> flex-direction: column </text>
          <text class="uni-subtitle-text"> 纵向布局 </text>
        </view>
        <view class="uni-flex uni-column">
          <view class="flex-item flex-item-V uni-bg-red"
            ><text style="color: #fff">A</text></view
          >
          <view class="flex-item flex-item-V uni-bg-green"
            ><text style="color: #fff">B</text></view
          >
          <view class="flex-item flex-item-V uni-bg-blue"
            ><text style="color: #fff">C</text></view
          >
        </view>
Y
init  
yurj26 已提交
48

DCloud-WZF's avatar
DCloud-WZF 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
        <view class="uni-title uni-common-mt">
          <text class="uni-title-text"> 更多布局示例 </text>
          <text class="uni-subtitle-text"> flex布局演示 </text>
        </view>
        <view>
          <view class="text-box"
            ><text class="text">纵向布局-自动宽度</text></view
          >
          <view class="text-box" style="width: 300rpx"
            ><text class="text">纵向布局-固定宽度</text></view
          >
          <view class="text-box"
            ><text class="text">横向布局-自动宽度</text></view
          >
          <view class="text-box"
            ><text class="text">横向布局-自动宽度</text></view
          >
        </view>
        <view
          class="uni-flex uni-row"
          style="-webkit-justify-content: center; justify-content: center"
        >
          <view class="text-box"><text class="text">横向布局-居中</text></view>
          <view class="text-box"><text class="text">横向布局-居中</text></view>
        </view>
        <view
          class="uni-flex uni-row"
          style="-webkit-justify-content: flex-end; justify-content: flex-end"
        >
          <view class="text-box"><text class="text">横向布局-居右</text></view>
          <view class="text-box"><text class="text">横向布局-居右</text></view>
        </view>
        <view class="uni-flex uni-row">
          <view class="text-box" style="-webkit-flex: 1; flex: 1"
            ><text class="text">横向布局-平均分布</text></view
          >
          <view class="text-box" style="-webkit-flex: 1; flex: 1"
            ><text class="text">横向布局-平均分布</text></view
          >
        </view>
        <view
          class="uni-flex uni-row"
          style="
            -webkit-justify-content: space-between;
            justify-content: space-between;
          "
        >
          <view class="text-box"
            ><text class="text">横向布局-两端对齐</text></view
          >
          <view class="text-box"
            ><text class="text">横向布局-两端对齐</text></view
          >
        </view>
        <view class="uni-flex uni-row">
          <view class="text-box" style="width: 200rpx"
            ><text class="text">固定宽度</text></view
          >
          <view class="text-box" style="-webkit-flex: 1; flex: 1"
            ><text class="text">自动占满余量</text></view
          >
        </view>
        <view class="uni-flex uni-row">
          <view class="text-box" style="width: 200rpx"
            ><text class="text">固定宽度</text></view
          >
          <view class="text-box" style="-webkit-flex: 1; flex: 1"
            ><text class="text">自动占满</text></view
          >
          <view class="text-box" style="width: 200rpx"
            ><text class="text">固定宽度</text></view
          >
        </view>
        <view
          class="uni-flex uni-row"
          style="-webkit-flex-wrap: wrap; flex-wrap: wrap"
        >
          <view class="text-box" style="width: 320rpx"
            ><text class="text">一行显示不全,wrap折行</text></view
          >
          <view class="text-box" style="width: 320rpx"
            ><text class="text">一行显示不全,wrap折行</text></view
          >
          <view class="text-box" style="width: 320rpx"
            ><text class="text">一行显示不全,wrap折行</text></view
          >
        </view>
        <view class="uni-flex uni-row">
          <view
            class="text-box"
            style="
              -webkit-flex: 1;
              flex: 1;
              height: 200rpx;
              -webkit-justify-content: center;
              justify-content: center;
              -webkit-align-items: flex-start;
              align-items: flex-start;
            "
          >
            <text class="text" style="line-height: 70rpx">垂直居顶</text>
          </view>
          <view
            class="text-box"
            style="
              -webkit-flex: 1;
              flex: 1;
              height: 200rpx;
              -webkit-justify-content: center;
              justify-content: center;
              -webkit-align-items: center;
              align-items: center;
            "
          >
            <text class="text">垂直居中</text>
          </view>
          <view
            class="text-box"
            style="
              -webkit-flex: 1;
              flex: 1;
              height: 200rpx;
              -webkit-justify-content: center;
              justify-content: center;
              -webkit-align-items: flex-end;
              align-items: flex-end;
            "
          >
            <text class="text" style="line-height: 70rpx">垂直居底</text>
          </view>
        </view>
Y
init  
yurj26 已提交
180

DCloud-WZF's avatar
DCloud-WZF 已提交
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
        <view class="uni-title uni-common-mt">
          <text class="uni-title-text"> 组合示例 </text>
          <text class="uni-subtitle-text"> flex布局演示 </text>
        </view>
        <view class="uni-flex uni-row">
          <view
            class="text-box uni-flex"
            style="
              width: 200rpx;
              height: 220rpx;
              -webkit-justify-content: center;
              justify-content: center;
              -webkit-align-items: center;
              align-items: center;
            "
          >
            <image
              src="/static/plus.png"
              style="width: 150rpx; height: 150rpx"
            ></image>
          </view>
          <view
            class="uni-flex uni-column"
            style="
              -webkit-flex: 1;
              flex: 1;
              -webkit-justify-content: space-between;
              justify-content: space-between;
            "
          >
            <view
              class="text-box"
              style="
                height: 120rpx;
                justify-content: start;
                align-items: start;
                padding-left: 20rpx;
              "
            >
              <text class="text" style="line-height: 70rpx"
                >文字居左,留出左间距</text
              >
Y
init  
yurj26 已提交
223 224
            </view>

DCloud-WZF's avatar
DCloud-WZF 已提交
225 226 227 228 229 230 231
            <view class="uni-flex uni-row">
              <view class="text-box" style="-webkit-flex: 1; flex: 1">
                <text class="text">剩余数量</text>
              </view>
              <view class="text-box" style="-webkit-flex: 1; flex: 1">
                <text class="text">立即购买</text>
              </view>
Y
init  
yurj26 已提交
232
            </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
233
          </view>
Y
init  
yurj26 已提交
234
        </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
235
      </view>
Y
init  
yurj26 已提交
236
    </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
237 238 239
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
Y
init  
yurj26 已提交
240 241
</template>
<script>
DCloud-WZF's avatar
DCloud-WZF 已提交
242 243 244 245 246
export default {
  data() {
    return {}
  },
}
Y
init  
yurj26 已提交
247 248 249
</script>

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
250 251 252 253 254 255 256
.flex-item {
  width: 33.3%;
  height: 200rpx;
  display: flex;
  justify-content: center;
  align-items: center;
}
Y
init  
yurj26 已提交
257

DCloud-WZF's avatar
DCloud-WZF 已提交
258 259 260 261 262 263
.flex-item-V {
  width: 100%;
  height: 150rpx;
  text-align: center;
  line-height: 150rpx;
}
Y
init  
yurj26 已提交
264

DCloud-WZF's avatar
DCloud-WZF 已提交
265 266 267 268 269 270 271 272 273 274
.text-box {
  margin: 15rpx 10rpx;
  padding: 0 20rpx;
  background-color: #ebebeb;
  height: 70rpx;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: row;
}
Y
init  
yurj26 已提交
275

DCloud-WZF's avatar
DCloud-WZF 已提交
276 277 278 279 280
.text {
  color: #777;
  font-size: 26rpx;
}
</style>