React+TS前台项目实战(二十二)-- 全局常用导出组件Export封装


前言

今天我们来封装一个带导出图标的导出组件。

Export组件

1. 功能分析

通过传入链接地址,规定要跳转的导出页面,或是直接通过链接导出数据

2. 代码+详细注释

// @/components/Export/index.tsx
import { useTranslation } from 'react-i18next'
import { Link } from '@/components/Link'
import styles from './styles.module.scss'
import { ReactComponent as ExportIcon } from './export.svg'

/**
 * 导出按钮组件
 * @param {Object} props - 组件属性
 * @param {string} props.link - 导出链接
 * @returns {JSX.Element} - 导出按钮
 */
export function Export({ link }: { link: string }) {
  const [t] = useTranslation()
  return (
    <Link className={styles.exportLink} to={link} target="_blank">
      {/* 按钮文本 */}
      <div>{t(`common.export`)}</div>
      {/* 导出图标 */}
      <ExportIcon />
    </Link>
  )
}
------------------------------------------------------------------------------
// @/components/Export/styles.module.scss
.exportLink {
  height: 50px;
  display: flex;
  align-items: center;
  color: var(--cd-primary-color);
  cursor: pointer;

  > div:first-child {
    margin-right: 8px;
    white-space: nowrap;
  }
}

3. 使用方式

// 引入组件
import Export from '@/components/Export'
// 使用
<Export link="/export?module=tranction" />

4. 效果展示

在这里插入图片描述


总结

下一篇讲【全局常用组件Echarts封装】。关注本栏目,将实时更新。

  • 16
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值