view.uvue 7.7 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
      <page-head title="view"></page-head>
7
      <view class="uni-padding-wrap uni-common-mt uni-common-mb">
DCloud-WZF's avatar
DCloud-WZF 已提交
8
        <view>
9
          <text class="uni-hello-text"> Flex是Flexible Box的缩写,意为“弹性布局”,用来为盒状模型提供最大的灵活性。当设置display: flex后,继续给view等容器组件设置flex-direction: row或column,就可以在该容器内按行或列排布子组件。uni-app推荐使用flex布局。因为flex布局有利于跨更多平台,尤其是采用原生渲染的平台。 </text>
DCloud-WZF's avatar
DCloud-WZF 已提交
10
        </view>
Y
init  
yurj26 已提交
11

DCloud-WZF's avatar
DCloud-WZF 已提交
12 13 14 15 16
        <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">
17 18 19
          <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>
DCloud-WZF's avatar
DCloud-WZF 已提交
20
        </view>
Y
init  
yurj26 已提交
21

DCloud-WZF's avatar
DCloud-WZF 已提交
22 23 24 25 26
        <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">
27 28 29
          <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>
DCloud-WZF's avatar
DCloud-WZF 已提交
30
        </view>
Y
init  
yurj26 已提交
31

DCloud-WZF's avatar
DCloud-WZF 已提交
32 33 34 35 36
        <view class="uni-title uni-common-mt">
          <text class="uni-title-text"> 更多布局示例 </text>
          <text class="uni-subtitle-text"> flex布局演示 </text>
        </view>
        <view>
37 38 39 40
          <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>
DCloud-WZF's avatar
DCloud-WZF 已提交
41
        </view>
42
        <view class="uni-flex uni-row" style="-webkit-justify-content: center; justify-content: center">
DCloud-WZF's avatar
DCloud-WZF 已提交
43 44 45
          <view class="text-box"><text class="text">横向布局-居中</text></view>
          <view class="text-box"><text class="text">横向布局-居中</text></view>
        </view>
46
        <view class="uni-flex uni-row" style="-webkit-justify-content: flex-end; justify-content: flex-end">
DCloud-WZF's avatar
DCloud-WZF 已提交
47 48 49 50
          <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">
51 52
          <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>
DCloud-WZF's avatar
DCloud-WZF 已提交
53
        </view>
54 55 56
        <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>
DCloud-WZF's avatar
DCloud-WZF 已提交
57 58
        </view>
        <view class="uni-flex uni-row">
59 60
          <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>
DCloud-WZF's avatar
DCloud-WZF 已提交
61 62
        </view>
        <view class="uni-flex uni-row">
63 64 65
          <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>
DCloud-WZF's avatar
DCloud-WZF 已提交
66
        </view>
67 68 69 70
        <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>
DCloud-WZF's avatar
DCloud-WZF 已提交
71 72
        </view>
        <view class="uni-flex uni-row">
73
          <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">
DCloud-WZF's avatar
DCloud-WZF 已提交
74 75
            <text class="text" style="line-height: 70rpx">垂直居顶</text>
          </view>
76
          <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">
DCloud-WZF's avatar
DCloud-WZF 已提交
77 78
            <text class="text">垂直居中</text>
          </view>
79
          <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">
DCloud-WZF's avatar
DCloud-WZF 已提交
80 81 82
            <text class="text" style="line-height: 70rpx">垂直居底</text>
          </view>
        </view>
Y
init  
yurj26 已提交
83

DCloud-WZF's avatar
DCloud-WZF 已提交
84 85 86 87 88
        <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">
89 90
          <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>
DCloud-WZF's avatar
DCloud-WZF 已提交
91
          </view>
92 93 94
          <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 已提交
95 96
            </view>

DCloud-WZF's avatar
DCloud-WZF 已提交
97 98 99 100 101 102 103
            <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 已提交
104
            </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
105
          </view>
Y
init  
yurj26 已提交
106
        </view>
107
        <button class="uni-common-mt" @click="goGeneralAttribute('/pages/component/view/view-draw')">DrawableContext</button>
DCloud-WZF's avatar
DCloud-WZF 已提交
108
      </view>
Y
init  
yurj26 已提交
109
    </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
110 111 112
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
Y
init  
yurj26 已提交
113 114
</template>
<script>
DCloud-WZF's avatar
DCloud-WZF 已提交
115
export default {
116
  methods: {
117
    goGeneralAttribute(path: string) {
118
      uni.navigateTo({
119
        url: path,
120
      })
121 122
    },
  },
DCloud-WZF's avatar
DCloud-WZF 已提交
123
}
Y
init  
yurj26 已提交
124 125 126
</script>

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
127 128 129 130 131 132 133
.flex-item {
  width: 33.3%;
  height: 200rpx;
  display: flex;
  justify-content: center;
  align-items: center;
}
Y
init  
yurj26 已提交
134

DCloud-WZF's avatar
DCloud-WZF 已提交
135 136 137 138
.flex-item-V {
  width: 100%;
  height: 150rpx;
}
Y
init  
yurj26 已提交
139

DCloud-WZF's avatar
DCloud-WZF 已提交
140 141 142 143 144 145 146 147 148 149
.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 已提交
150

DCloud-WZF's avatar
DCloud-WZF 已提交
151 152 153 154 155
.text {
  color: #777;
  font-size: 26rpx;
}
</style>