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

文章目录

  • 前言
  • Export组件
    • [1. 功能分析](#1. 功能分析)
    • [2. 代码+详细注释](#2. 代码+详细注释)
    • [3. 使用方式](#3. 使用方式)
    • [4. 效果展示](#4. 效果展示)
  • 总结

前言

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

Export组件

1. 功能分析

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

2. 代码+详细注释

c 复制代码
// @/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. 使用方式

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

4. 效果展示


总结

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

相关推荐
独泪了无痕7 小时前
使用Fetch API 探索前后端数据交互
前端·http·交互设计
css趣多多7 小时前
别名路径的知识点
前端
靓仔建9 小时前
Vue3导入组件出错does not provide an export named ‘user_setting‘ (at index.vue:180:10)
开发语言·前端·typescript
EnoYao9 小时前
我写了一个团队体检报告 Skill,把摸鱼的同事扒出来了😅
前端·javascript
梁正雄10 小时前
Python前端-2-css练习
前端·css·python
清汤饺子10 小时前
用 Cursor 半年了,效率还是没提升?是因为你没用对这 7 个功能
前端·后端·cursor
蓝莓味的口香糖10 小时前
【vue3】组件的批量全局注册
前端·javascript·vue.js
wefly201710 小时前
开发者效率神器!jsontop.cn一站式工具集,覆盖开发全流程高频需求
前端·后端·python·django·flask·前端开发工具·后端开发工具
独泪了无痕10 小时前
自动导入 AutoImport:告别手动引入依赖,优化Vue3开发体验
前端·vue.js·typescript
GDAL11 小时前
MANIFEST.in简介
linux·服务器·前端·python