1.用line-height的值和view的height值一样
wxml:
<view class='container'>
这是个例子
</view>
wxss:
.container{
border: 2rpx black solid;
width: 400rpx;
height: 200rpx;
text-align: center;
line-height: 200rpx;
}
效果:
2.用flex布局
wxml:
<view class='container'>
<text>这是个例子
</text>
</view>
wxss:
.container{
border: 2rpx black solid;
width: 400rpx;
height: 200rpx;
display: flex;
flex-direction: column;