wxc-flex
常见布局 - 水平垂直居中
<wxc-flex class="wrap" main="center" cross="center">
<view class="item"></view>
<view class="item"></view>
</wxc-flex>
<view class="layout-code">
<wxc-flex <view class="layout-code__point">main="center" cross="center"</view>>...</wxc-flex>
</view>
</template>
<script>
export default {
config: {
usingComponents: {
'wxc-flex': '@minui/wxc-flex'
}
},
data: {},
methods: {}
}
</script>
<style>
.wrap {
display: block;
height: 300rpx;
padding: 10rpx;
background: #696969;
}
.item {
min-width: 100rpx;
min-height: 100rpx;
}
.item:nth-of-type(odd) {
background: #afdde3
}
.item:nth-of-type(2n) {
background: #f397b2
}
.layout-code {
padding: 15rpx;
background: #222222;
color: #FFFFFF;
font-size: 20rpx;
font-family: Monaco;
}
.layout-code__point {
display: inline-block;
padding: 0 5rpx;
background: #444444;
}
</style>
交叉轴排列
项目在交叉轴上如何对齐
主轴方向
<template>
<wxc-flex class="wrap" dir="{{dir}}">
<view class="item">栏 1</view>
<view class="item">栏 2</view>
</wxc-flex>
<view class="layout-code">
<wxc-flex <view class="layout-code__point">dir="{{dir}}"</view>>...</wxc-flex>
</view>
<view class="setting-button" bindtap="setDirToLeft">水平正序(默认)</view>
<view class="setting-button" bindtap="setDirToRight">水平倒序</view>
<view class="setting-button" bindtap="setDirToBottom">垂直倒序</view>
</template>
<script>
export default {
config: {
usingComponents: {
'wxc-flex': '@minui/wxc-flex'
}
},
data: {
dir: 'left'
},
/** note: 在 wxp 文件或者页面文件中请去掉 methods 包装 */
methods: {
setDirToLeft: function () {
this.setData({
dir: 'left'
})
},
setDirToRight: function () {
this.setData({
dir: 'right'
})
},
setDirToTop: function () {
this.setData({
dir: 'top'
})
},
setDirToBottom: function () {
this.setData({
dir: 'bottom'
})
}
}
}
</script>
<style>
.wrap {
display: block;
padding: 10rpx;
background: #696969;
}
.item {
min-width: 100rpx;
min-height: 100rpx;
font-size: 22rpx;
text-align: center;
}
.item:nth-of-type(odd) {
line-height: 30rpx;
background: #afdde3
}
.item:nth-of-type(2n) {
line-height: 50rpx;
background: #f397b2
}
.setting-button {
display: inline-block;
line-height: 50rpx;
margin: 20rpx 10rpx 0 0;
padding: 2rpx 20rpx;
border-radius: 6rpx;
color: #ffffff;
font-size: 18rpx;
text-align: center;
}
.layout-code {
padding: 15rpx;
background: #222222;
color: #FFFFFF;
font-size: 20rpx;
font-family: Monaco;
}
.layout-code__point {
display: inline-block;
padding: 0 5rpx;
background: #444444;
}
</style>
常见布局 - 定宽+弹性宽度
常见布局 - 列表
<template>
<wxc-flex class="wrap" cross="top" wrap="wrap">
<view class="item"></view>
<view class="item"></view>
<view class="item"></view>
<view class="item"></view>
<view class="item"></view>
</wxc-flex>
</template>
<script>
export default {
config: {
usingComponents: {
'wxc-flex': '@minui/wxc-flex'
}
},
data: {},
methods: {}
}
</script>
<style>
.wrap {
display: block;
padding: 2%;
background: #696969;
}
.item {
width: 47%;
height: 348rpx;
margin: 1.5%;
flex-grow: 0;
}
.item:nth-of-type(odd) {
background: #afdde3
}
.item:nth-of-type(2n) {
background: #f397b2
}
</style>
项目在主轴上的对齐方式
换行选项
如果一条轴线排不下,如何换行
<template>
<wxc-flex class="wrap" wrap="{{wrap}}">
<view class="item">栏 1</view>
<view class="item">栏 2</view>
<view class="item">栏 3</view>
<view class="item">栏 4</view>
<view class="item">栏 5</view>
<view class="item">栏 6</view>
<view class="item">栏 7</view>
<view class="item">栏 8</view>
<view class="item">栏 9</view>
<view class="item">栏 10</view>
<view class="item">栏 11</view>
<view class="item">栏 12</view>
</wxc-flex>
<view class="layout-code">
<wxc-flex <view class="layout-code__point">wrap="{{wrap}}"</view>>...</wxc-flex>
</view>
<view class="setting-button" bindtap="setWrapToNowrap">不换行(默认)</view>
<view class="setting-button" bindtap="setWrapToWrap">正序换行</view>
<view class="setting-button" bindtap="setWrapToReverse">倒序换行</view>
</template>
<script>
export default {
config: {
usingComponents: {
'wxc-flex': '@minui/wxc-flex'
}
},
data: {
wrap: 'nowrap'
},
/** note: 在 wxp 文件或者页面文件中请去掉 methods 包装 */
methods: {
setWrapToNowrap: function () {
this.setData({
wrap: 'nowrap'
})
},
setWrapToWrap: function () {
this.setData({
wrap: 'wrap'
})
},
setWrapToReverse: function () {
this.setData({
wrap: 'reverse'
})
}
}
}
</script>
<style>
.wrap {
display: block;
padding: 10rpx;
background: #696969;
}
.item {
min-width: 20%;
min-height: 100rpx;
font-size: 22rpx;
text-align: center;
}
.item:nth-of-type(odd) {
line-height: 30rpx;
background: #afdde3
}
.item:nth-of-type(2n) {
line-height: 50rpx;
background: #f397b2
}
.setting-button {
display: inline-block;
line-height: 50rpx;
margin: 20rpx 10rpx 0 0;
padding: 2rpx 20rpx;
border-radius: 6rpx;
background: #31b0d5;
color: #ffffff;
font-size: 18rpx;
text-align: center;
}
.layout-code {
padding: 15rpx;
background: #222222;
color: #FFFFFF;
font-size: 20rpx;
font-family: Monaco;
}
.layout-code__point {
display: inline-block;
padding: 0 5rpx;
background: #444444;
}
</style>
Flex【props】
地址 | |
---|---|
flex 组件文档 https://meili.github.io/min/docs/minui/index.html#flex | |
flex 组件源码 | |
MinUI 组件库 https://github.com/meili/minui |
v1.0.3(2018.6.5)
- 增加点击事件。
v1.0.2(2017.11.02)
- update .npmignore