分组(group)组件是将组件分组,添加间隔,以产生明显的区块,主要用于负一屏分类、通讯录分组等场景。
分组一般具有如下特点:
效果图如下:

基本布局代码如下:
<template>
<div class="container">
<text class="title">基础分组</text>
<group>
<text class="txt" for="{{listdata}}">{{ $item }}</text>
</group>
</div>
</template>
<template>
<div class="{{mode?'card':'container'}}" style="margin-top: {{top}}px;">
<div style="flex-direction: column;">
<text class="title">{{ title }}</text>
<div style="margin-top: {{top}}px;flex-direction: column;">
<slot></slot>
</div>
</div>
</div>
</template> 属性 |
类型 |
默认值 |
描述 |
|---|---|---|---|
title |
String |
- |
标题内容。 |
top |
Number |
0 |
标题与分组内容的间隔。 |
mode |
Boolean |
false |
分组组件的模式。
|
支持的事件:
无
data: {
title: "",
top: 0,
mode: false
}, <group top="20" mode="{{mode}}" title="卡片模式">
<text class="txt" for="{{listdata}}">{{ $item }}</text>
</group> 分组group.ux代码:
<template>
<!-- Only one root node is allowed in template. -->
<div class="{{mode?'card':'container'}}" style="margin-top: {{top}}px;">
<div style="flex-direction: column;">
<text class="title">{{ title }}</text>
<div style="margin-top: {{top}}px;flex-direction: column;">
<slot></slot>
</div>
</div>
</div>
</template>
<style>
.container {
flex-direction: column;
background-color: white;
}
.title {
font-size: 50px;
background-color: #afd44a;
}
.card {
border-radius: 15px;
margin-left: 20px;
margin-right: 20px;
flex-direction: column;
background-color: rgb(230, 172, 119);
}
</style>
<script>
module.exports = {
data: {
title: "",
top: 0,
mode: false
},
onInit() {
this.$page.setTitleBar({
text: 'menu',
textColor: '#ffffff',
backgroundColor: '#007DFF',
backgroundOpacity: 0.5,
menu: true
});
}
}
</script>
页面hello.ux代码:
<import name="group" src="../Group/group.ux"></import>
<template>
<!-- Only one root node is allowed in template. -->
<div class="container">
<text class="title">基础分组</text>
<group>
<text class="txt" for="{{listdata}}">{{ $item }}</text>
</group>
<group top="20" title="基础模式">
<text class="txt" for="{{listdata}}">{{ $item }}</text>
</group>
<text class="title">卡片分组</text>
<group mode="{{mode}}">
<text class="txt" for="{{listdata}}">{{ $item }}</text>
</group>
<group top="20" mode="{{mode}}" title="卡片模式">
<text class="txt" for="{{listdata}}">{{ $item }}</text>
</group>
</div>
</template>
<style>
.container {
flex-direction: column;
background-color: #cececc;
}
.title {
font-size: 50px;
width: 100%;
margin-bottom: 20px;
margin-top: 30px;
background-color: #4ab9d4;
}
.txt {
font-size: 50px;
}
</style>
<script>
module.exports = {
data: {
mode: true,
listdata: ["分组内容", "分组内容", "分组内容"]
},
onInit() {
this.$page.setTitleBar({
text: 'menu',
textColor: '#ffffff',
backgroundColor: '#007DFF',
backgroundOpacity: 0.5,
menu: true
});
}
}
</script>