Grid 九宫格

定义/Definition

卡片可以控制和组织信息,通常是更复杂或详细信息的切入点。

规则 / Rule

九宫格内文本最长不超过五个字符。

代码演示

基本

  1. import { Grid } from 'antd-mobile';
  2. let data1 = [
  3. {
  4. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  5. text: '名字',
  6. link: 'hehe',
  7. }, {
  8. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  9. text: '名字',
  10. link: 'hehe',
  11. }, {
  12. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  13. text: '名字',
  14. link: 'hehe',
  15. }, {
  16. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  17. text: '名字',
  18. link: 'hehe',
  19. }, {
  20. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  21. text: '名字',
  22. link: 'hehe',
  23. }, {
  24. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  25. text: '名字',
  26. link: 'hehe',
  27. }, {
  28. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  29. text: '名字',
  30. link: 'hehe',
  31. }, {
  32. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  33. text: '名字',
  34. link: 'hehe',
  35. }, {
  36. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  37. text: '名字',
  38. link: 'hehe',
  39. }, {
  40. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  41. text: '名字',
  42. link: 'hehe',
  43. },
  44. ];
  45. let GridExample = React.createClass({
  46. render() {
  47. return (<div>
  48. <Grid data={data1} />
  49. </div>);
  50. },
  51. });
  52. ReactDOM.render(<GridExample />, mountNode);

没有边线

  1. import { Grid } from 'antd-mobile';
  2. let data2 = [
  3. {
  4. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  5. text: '名字',
  6. link: 'hehe',
  7. }, {
  8. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  9. text: '名字',
  10. link: 'hehe',
  11. }, {
  12. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  13. text: '名字',
  14. link: 'hehe',
  15. }, {
  16. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  17. text: '名字',
  18. link: 'hehe',
  19. }, {
  20. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  21. text: '名字',
  22. link: 'hehe',
  23. }, {
  24. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  25. text: '名字',
  26. link: 'hehe',
  27. }, {
  28. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  29. text: '名字',
  30. link: 'hehe',
  31. }, {
  32. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  33. text: '名字',
  34. link: 'hehe',
  35. }, {
  36. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  37. text: '名字',
  38. link: 'hehe',
  39. }, {
  40. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  41. text: '名字',
  42. link: 'hehe',
  43. },
  44. ];
  45. let GridExample = React.createClass({
  46. render() {
  47. return (<div>
  48. <Grid
  49. data={data2}
  50. hasLine={false}
  51. />
  52. </div>);
  53. },
  54. });
  55. ReactDOM.render(<GridExample />, mountNode);

走马灯有边线

  1. import { Grid } from 'antd-mobile';
  2. let data3 = [
  3. {
  4. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  5. text: '名字',
  6. link: 'hehe',
  7. }, {
  8. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  9. text: '名字',
  10. link: 'hehe',
  11. }, {
  12. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  13. text: '名字',
  14. link: 'hehe',
  15. }, {
  16. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  17. text: '名字',
  18. link: 'hehe',
  19. }, {
  20. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  21. text: '名字',
  22. link: 'hehe',
  23. }, {
  24. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  25. text: '名字',
  26. link: 'hehe',
  27. }, {
  28. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  29. text: '名字',
  30. link: 'hehe',
  31. }, {
  32. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  33. text: '名字',
  34. link: 'hehe',
  35. }, {
  36. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  37. text: '名字',
  38. link: 'hehe',
  39. }, {
  40. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  41. text: '名字',
  42. link: 'hehe',
  43. },
  44. ];
  45. let GridExample = React.createClass({
  46. render() {
  47. return (<div>
  48. <Grid
  49. data={data3}
  50. isCarousel
  51. onClick={(el, index) => { alert(index); }}
  52. needActive={false}
  53. />
  54. </div>);
  55. },
  56. });
  57. ReactDOM.render(<GridExample />, mountNode);

走马灯没有边线

  1. import { Grid } from 'antd-mobile';
  2. let data4 = [
  3. {
  4. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  5. text: '名字',
  6. link: 'hehe',
  7. }, {
  8. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  9. text: '名字',
  10. link: 'hehe',
  11. }, {
  12. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  13. text: '名字',
  14. link: 'hehe',
  15. }, {
  16. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  17. text: '名字',
  18. link: 'hehe',
  19. }, {
  20. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  21. text: '名字',
  22. link: 'hehe',
  23. }, {
  24. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  25. text: '名字',
  26. link: 'hehe',
  27. }, {
  28. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  29. text: '名字',
  30. link: 'hehe',
  31. }, {
  32. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  33. text: '名字',
  34. link: 'hehe',
  35. }, {
  36. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  37. text: '名字',
  38. link: 'hehe',
  39. }, {
  40. icon: 'https://os.alipayobjects.com/rmsportal/IptWdCkrtkAUfjE.png',
  41. text: '名字',
  42. link: 'hehe',
  43. },
  44. ];
  45. let GridExample = React.createClass({
  46. render() {
  47. return (<div>
  48. <Grid
  49. data={data4}
  50. hasLine={false}
  51. isCarousel
  52. />
  53. </div>);
  54. },
  55. });
  56. ReactDOM.render(<GridExample />, mountNode);

Grid九宫格 - 图1

API

Grid

成员说明类型可选值默认值
data传入的菜单数据Array,每个元素必须包含icon,和text两个key[]
onClick点击每个菜单的回调Function(el, index)
hasLine是否有边框bolleantrue
isCarousel是否跑马灯,bolleanfalse