有需求需要实现表格的列宽拖拉可变,在开始拖拉和放下的过程中在行头显示一条虚线表标明位置,鼠标释放后刷新表格。
上代码!
1. 拖拉传参组件代码
import { FC, useState } from 'react'
import { Resizable } from 'react-resizable'
// 引入react-resizable npm i xxx 或 yarn add xxx
import { deBounce } from '@/utils/utilConvenrt'
// 防抖函数,不是一定需要,目的:更新偏移量不要实时更新
import classnames from 'classnames'
const ResizableTitle: FC<any> = (props) => {
const { onResize, width, ...restProps } = props;
// 添加偏移量
const [offset, setOffset] = useState<number>(0)
if (!width) {
return <th {...restProps} />
}
return (
<Resizable
width={Number(width) + Number(offset)}
height={0}
handle={
<span
// 有偏移量显示竖线
className={classnames(['react-resizable-handle', offset && 'active'])}
// 拖拽层偏移
style={
{ tra