1.获取ref数据
import React, { useRef } from 'react'
const ECharts = () => {
const echartRef = useRef()
console.log(echartRef.current)
return (
<div ref={echartRef} style={style}>
1231232
</div>
)
}
export default ECharts
2.设置数据
import React, { useState } from 'react'
//定义默认数据
const [tableDate, setTableDate] = useState([])
//给默认数据赋值
setTableDate(['123','234'])
3.获取dom后触发的事件(和mounted类似)
import React, { useEffect } from 'react'
useEffect(() => {
console.log('123')
})
}, [])
注意: useEffect 中第二个参数中得到数据发生变化会再次触发这个方法
4.事件触发
import { Button } from 'antd'
const user = () => {
const handleClick = (data) => {
console.log(data)
}
return (
<Button type="primary" onClick={()=>handleClick('add')}>aa</Button>
)
}
export default user
5.动态获取图标
import React from 'react'
import * as Icon from '@ant-design/icons'
// 动态获取icon
const iconToElement = (item) => React.createElement(Icon[item])
iconToElement(图标字段)