// utils.js
// 获取当前浏览器窗口大小的方法
export const useClientSize =()=> {
const [ layout, setLayout]= useState({ height: innerHeight, width: innerWidth })
const onResize = useCallback(
()=> {
setLayout({
height: innerHeight,
width: innerWidth
})
}, [])
useEffect(()=> {
window.addEventListener('resize', onResize)
return () =>{
window.removeEventListener('resize', onResize)
}
}, [])
return layout
}
数组:每三个分组, 数组分组
const tempList = []
for (let i=0; i<list.length; i=i+3) {
tempList.push( [list.slice(i, i+3)] )
}
useMemo使用场景,状态作为 依赖项 驱动更新。
const columns = React.useMemo(() => [
{
datalndex: 'name',
title:'Test',
width: locale? 200:80,
},
...
],[locale])
图片按比例缩放,在元素内联样式上设置宽or高
width: auto; height: auto;
max-width: 100%;
max-height: 100%;
复制粘贴
const copyText =()=>{
const clipboard = new Clipboard(`#copy_link`)
clipboard.on('success', function (e: any){
message.success("复制成功", 1)
e.clearSelection();
})
return ()=>{
clipboard.destroy()
}
}
修改url地址,但不刷新页面
window.history.pushState({}, 0, window.location.href + '?type=china');