text.length==0?'pages-icon-wrapper-no-bg':'pages-icon-wrapper'}}".
另外一点,由于我们是将该界面文件作为模板的,所以必须要用template标记来包住,同时命一个名字name,这样在引用模板的地方才可以识别调用。 现在我们在index.wxml中引用这个模板
<!--index.wxml-->
<import src="cell.wxml" />
<view class="pages-container">
<scroll-view scroll-y="true" class="pages-wrapper">
<view wx:for="{{pageItems}}" wx:key="{{text}}">
<view class="pages-row">
<template is="cell" data="{{...item[0],cellHeight}}" />
<template is="cell" data="{{...item[1],cellHeight}}" />
<template is="cell" data="{{...item[2],cellHeight}}" />
</view>
</view>
</scroll-view>
</view>模板的引用使用import来引用,在调用的地方使用template和is,其中is指定的是cell.wxml中的name。item[0]、item[1]、item[2]是循环传入的数据,cellHeight是在index.js的data中存放的数据。在将数据传入到模板内部时,框架会将其展开在字段的形式,即key-value对,所以再看cell.wxml文件,就会发现内部是直接使用key来作为数据的。 将数据呈现到界面之后,我们需要相当的样式来配合,index.wxss代码如下。
/**index.wxss**/
.pages-container {
height: 100%;
display: flex;
flex-direction: column;
box-sizing: border-box;
padding-top: 10rpx;
padding-bottom: 10rpx;
}
.pages-title-bg {
width: 100%;
}
.pages-wrapper {
}
.pages-row {
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-around;
}
.pages-item {
position: relative;
padding: 10rpx;
width: 33%;
background-color: #fff;
border: #ddd solid 1px;
}
.pages-icon-wrapper {
display: flex;
justify-content: space-around;
align-items: center;
margin: 10rpx;
border-radius: 30%;
height: 75%;
background:#00CD0D;
}
.pages-icon-wrapper-no-bg {
display: flex;
justify-content: space-around;
align-items: center;
margin: 10rpx;
height: 75%;
}
.pages-icon {
width: 100rpx;
height: 100rpx;
}
.pages-text-wrapper {
text-align: center;
}
.pages-text {
font-weight: bolder;
}效果如下图

我们模板中使用navigator元素来呈现格子,所以每个格子自然就可以导航了。
以上就是小程序开发九宫格界面的导航的代码实现的详细内容,更多请关注php中文网其它相关文章!
小程序是一种不需要下载安装即可使用的应用,它实现了应用“触手可及”的梦想,用户扫一扫或者搜一下即可打开应用。
关键词:小程序开发9宫格界面的导航的代码完成