视图容器组件view是微信小程序开发中最常用的组件之一
类似于HTML中的div标签,是做页面布局的主要容器
view组件的属性如表3.5所示
| 属性名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| hover-class | String | none | 指定按下去的样式类,当hover-class=”none”时。没有单机态效果 |
| hover-stop-propagation | Boolean | false | 指定是否组织本节点的祖先节点出现单击态 |
| hover-start-time | Number | 50 | 按住后多久出现单击态,单位为ms |
| hover-stay-time | Number | 400 | 手指松开后单击态保留事件,单位为ms |
写微信小程序页面布局时,经常会使用flex的布局方式
因为微信小程序运行在微信中,所以不用考虑浏览器兼容的问题,可以放心使用flex布局
flex布局的使用如示例3-5所示
index.wxml<view class="container"><view style="font-size:24px;">flex布局</view><text>flex-direction:row</text><view class="flex-row"><view class="flex-row-item color-red"></view><view class="flex-row-item color-green"></view><view class="flex-row-item color-blue"></view></view><text>flex-direction:column</text><view class="flex-column"><view class="flex-column-item color-red"></view><view class="flex-column-item color-green"></view><view class="flex-column-item color-blue"></view></view></view>-------------------------------------------------------------------------------index.wxss.container{display: block;text-align: center;}.flex-row{display: flex;flex-direction: row;}.flex-row-item{height: 100px;flex: 1;}.flex-column{display: flex;width: 100px;flex-direction: column;}.flex-column-item{flex: 1;height: 100px;width: 100px;}.color-red{background-color: rgb(255, 0, 119);}.color-green{background-color: rgb(28, 179, 28);}.color-blue{background-color: rgb(31, 166, 255);}
示例3-5中使用flex进行了横向和纵向的布局,显示效果如图3.5所示

