优化这个布局<view class="box"> <uni-row class="demo-uni-row"> <uni-col :span="12"> <view class="boxnormal"> <text class="normaltext">正常气罐\n</text> <text class="normalSize">{{normalNumber}}</text> </view> </uni-col> <uni-col :span="12"> <view> <view class="warning"> <text class="warningtext">预警</text> <text class="warningSize">{{warningNumber}}</text> </view> <view class="error"> <text class="errortext">警告</text> <text class="errorSize">{{errorNumber}}</text> </view> </view> </uni-col> </uni-row> </view>
时间: 2023-07-19 15:23:09 浏览: 134
可以通过以下方式对这个布局进行优化:
1. 使用flex布局代替uni-row和uni-col布局,可以减少代码量,提高布局效率。
```
<view class="box">
<view class="boxnormal">
<text class="normaltext">正常气罐</text>
<text class="normalSize">{{normalNumber}}</text>
</view>
<view class="warning">
<text class="warningtext">预警</text>
<text class="warningSize">{{warningNumber}}</text>
</view>
<view class="error">
<text class="errortext">警告</text>
<text class="errorSize">{{errorNumber}}</text>
</view>
</view>
.box {
display: flex;
justify-content: space-between;
}
.boxnormal {
display: flex;
flex-direction: column;
align-items: center;
}
.warning, .error {
display: flex;
flex-direction: column;
align-items: center;
}
.warning {
background-color: #f5a623;
}
.error {
background-color: #f44336;
}
```
2. 将重复的样式封装成class,减少重复代码。
```
<view class="box">
<view class="boxnormal normal">
<text class="normaltext">正常气罐</text>
<text class="normalSize">{{normalNumber}}</text>
</view>
<view class="warning normalSize warningSize">预警 {{warningNumber}}</view>
<view class="error normalSize errorSize">警告 {{errorNumber}}</view>
</view>
.box {
display: flex;
justify-content: space-between;
}
.normal {
display: flex;
flex-direction: column;
align-items: center;
}
.warning {
background-color: #f5a623;
}
.error {
background-color: #f44336;
}
```
阅读全文