Grid 九宫格
在水平和垂直方向,将布局切分成若干等大的区块。
规则
- 区块中的内容应该是同类元素,eg:都是图片,或者都是图标+文字。
代码演示
基本
import { Grid } from 'antd-mobile';
const data1 = [
{
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
},
];
const GridExample = React.createClass({
render() {
return (<div>
<Grid data={data1} />
</div>);
},
});
ReactDOM.render(<GridExample />, mountNode);
没有边线
import { Grid } from 'antd-mobile';
const data2 = [
{
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
},
];
const GridExample = React.createClass({
render() {
return (<div>
<Grid
data={data2}
hasLine={false}
columnNum={3}
/>
</div>);
},
});
ReactDOM.render(<GridExample />, mountNode);
走马灯有边线
import { Grid } from 'antd-mobile';
const data3 = [
{
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
},
];
const GridExample = React.createClass({
render() {
return (<div>
<Grid
data={data3}
columnNum={3}
carouselMaxRow={3}
isCarousel
onClick={(el, index) => { alert(index); }}
/>
</div>);
},
});
ReactDOM.render(<GridExample />, mountNode);
走马灯没有边线
import { Grid } from 'antd-mobile';
const data4 = [
{
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
text: '名字',
link: 'hehe',
},
];
const GridExample = React.createClass({
render() {
return (<div>
<Grid
data={data4}
hasLine={false}
isCarousel
/>
</div>);
},
});
ReactDOM.render(<GridExample />, mountNode);
自定义
import { Grid } from 'antd-mobile';
const data1 = [
{
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
img: 'https://zos.alipayobjects.com/rmsportal/wIjMDnsrDoPPcIV.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
img: 'https://zos.alipayobjects.com/rmsportal/wIjMDnsrDoPPcIV.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
img: 'https://zos.alipayobjects.com/rmsportal/wIjMDnsrDoPPcIV.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
img: 'https://zos.alipayobjects.com/rmsportal/wIjMDnsrDoPPcIV.png',
text: '名字',
link: 'hehe',
}, {
icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
img: 'https://zos.alipayobjects.com/rmsportal/wIjMDnsrDoPPcIV.png',
text: '名字',
link: 'hehe',
},
];
const GridExample = React.createClass({
render() {
return (<div>
<Grid
data={data1}
columnNum={3}
hasLine={false}
renderItem={(dataItem, index) => (
<div style={{ margin: '16px', background: '#f7f7f7', textAlign: 'center' }}>
<div style={{ background: 'rgba(0, 0, 0, 0.1)', padding: '8px' }}>
<span>{index + 1}.{dataItem.text}</span>
</div>
<img src={dataItem.img} style={{ width: '80%', margin: '12px' }} />
</div>
)}
/>
</div>);
},
});
ReactDOM.render(<GridExample />, mountNode);
API
Grid
成员 | 说明 | 类型 | 可选值 | 默认值 |
---|
data | 传入的菜单数据 | Array,每个元素必须包含icon ,和text 两个key | | [] |
onClick | 点击每个菜单的回调 | Function(el, index) | | |
columnNum | 列数 | number | | 4 |
hasLine | 是否有边框 | boolean | | true |
isCarousel | 是否跑马灯, | boolean | | false |
carouselMaxRow | 如果是跑马灯, 一页跑马灯需要展示的行数 | number | | 2 |
renderItem | 自定义每个grid的条目的创建 | Function(el, index), 返回一个React.Element | | |