微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Ant Design 入门-参照官方文档使用组件

先来一个按钮组件使用的对比,官方文档的(不能直接用)和实际能用的。

官网demo:

<pre class="has">
import { Table,Divider,Tag } from 'antd';

const columns = [{
title: 'Name',dataIndex: 'name',key: 'name',render: text => <a href="javascript:;">{text},},{
title: 'Age',dataIndex: 'age',key: 'age',{
title: 'Address',dataIndex: 'address',key: 'address',{
title: 'Tags',key: 'tags',dataIndex: 'tags',render: tags => (

{tags.map(tag => {tag})}

),{
title: 'Action',key: 'action',render: (text,record) => (

<a href="javascript:;">Invite {record.name}

),}];

const data = [{
key: '1',name: 'John Brown',age: 32,address: 'New York No. 1 Lake Park',tags: ['nice','developer'],{
key: '2',name: 'Jim Green',age: 42,address: 'London No. 1 Lake Park',tags: ['loser'],{
key: '3',name: 'Joe Black',address: 'Sidney No. 1 Lake Park',tags: ['cool','teacher'],}];

ReactDOM.render(

,mountNode);

自己写的:

<pre class="has">
import { Table,Tag } from 'antd';
import React,{ Component } from 'react';
export default class MiniappList extends Component {
render() {
const columns = [{
title: 'Name',{
title: 'Tags',render: tags => (

{tags.map(tag => {tag})}

),{
title: 'Action',record) => (

<a href="javascript:;">Invite {record.name}

),}];
const data = [{
  key: '1',{
  key: '2',}];
return(<Table columns={columns} dataSource={data} />);

}
}

自己写的和文档的区别:

1. 需要引用react并且继承Component

2.导出类

3.使用 Component 的 render 函数标签放到 return 里面    -----完成

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐