微信小程序?qū)崿F(xiàn)九宮格,小程序九宮格布局怎么做
2020-09-27
導讀:小程序九宮格的實現(xiàn)有幾種方法,這里推薦用weui比較方便。
...
小程序九宮格的實現(xiàn)有幾種方法,這里推薦用weui比較方便。
下面是實現(xiàn)步驟:
.js中添加數(shù)據(jù)
Page({
/**
* 頁面的初始數(shù)據(jù)
*/
data: {
routers :[
{
text: '我的賬戶',
icon: '../../images/mine/mine_account.png',
url: '../myAccount/myAccount',
},
{
text: '我的合同',
icon: '../../images/mine/mine_contract.png',
url: '../myAccount/myAccount',
},
{
text: '瀏覽記錄',
icon: '../../images/mine/mine_browing.png',
url: '../myAccount/myAccount',
},
{
text: '我要出租',
icon: '../../images/mine/mine_lease.png',
url: '../myAccount/myAccount',
},
{
text: '客服',
icon: '../../images/mine/mine_customService.png',
url: '../myAccount/myAccount',
},
{
text: '我的收藏',
icon: '../../images/mine/mine_collect.png',
url: '../myAccount/myAccount',
}
]
},
})
.wxml中,添加weui-grids
<view class="weui-grids">
<view class="weui-grid" wx:for="{{routers}}" wx:key="name">
<navigator url="{{item.url}}">
<view class="weui-grid__icon">
<image src=" {{item.icon}}" mode="scaleToFill" />
</view>
<text class="weui-grid__label">{{item.text}}</text>
</navigator>
</view>
</view>
wxss中設(shè)置樣式
.weui-grids {
position: relative;
overflow: hidden;
margin-top: 10rpx;
}
.weui-grids:before {
content: " ";
position: absolute;
left: 0;
top: 0;
right: 0;
height: 1px;
border-top: 1px solid #D9D9D9;
color: #D9D9D9;
-webkit-transform-origin: 0 0;
transform-origin: 0 0;
-webkit-transform: scaleY(0.5);
transform: scaleY(0.5);
}
.weui-grids:after {
content: " ";
position: absolute;
left: 0;
top: 0;
width: 1px;
bottom: 0;
border-left: 1px solid #D9D9D9;
color: #D9D9D9;
-webkit-transform-origin: 0 0;
transform-origin: 0 0;
-webkit-transform: scaleX(0.5);
transform: scaleX(0.5);
}
.weui-grid {
position: relative;
float: left;
padding: 20px 10px;
width: 33.33333333%;
box-sizing: border-box;
background-color: white;
}
.weui-grid:before {
content:
第二部分:如何開通一個小商店