yarn add fetch-mock
- import mockFetch from 'fetch-mock';
-
- type IIcon = {
- icon: object;
- title: string;
- };
-
- const iconsIndex: IIcon[] = [
- {
- icon: require('@/assets/images/app/dashboard-contract.png'),
- title: '合同看板',
- },
- {
- icon: require('@/assets/images/app/dashboard-budget.png'),
- title: '预算看板',
- },
- ];
-
- mockFetch.mock(/index\/indexIcons/, {
- code: 200,
- data: iconsIndex,
- });
- //App.tsx中
- import '@/mock/index';
- import {defHttp} from '@/utils/http';
-
- enum Api {
- INDEX_ICON = '/index/indexIcons',
- }
-
- export function getIndexIcon() {
- return defHttp.get<any>(Api.INDEX_ICON);
- }
- import {getIndexIcon} from '@/api/PageIndex';
-
- // 页面主体
- class Index extends Component {
- state = {
- icons: [],
- };
-
- componentDidMount() {
- getIndexIcon().then((res: any) => {
- this.setState({icons: res.data});
- });
- }
- }