import React, { useEffect } from ‘react’;
// import { getHeroList } from ‘…/…/services/heros’
import { connect, Dispatch } from ‘umi’
const HeroMall = (props: any) => {
console.log(props)
useEffect(() => {
let { dispatch } = props
dispatch({
type: ‘heros/fetchHeroList’,
})
}, [])
// fetch(‘/api/herolist’).then(res=>{
// //console.log(res)
// return res.json()
// }).then(res=>{
// console.log(res)
// })
// fetch(‘/api/heros’).then(res=>{
// //console.log(res)
// return res.json()
// }).then(res=>{
// console.log(res)
// })
// getHeroList().then((res)=>{
// console.log(res)
// })
let { heros } = props
let herolist = heros && heros.herolist && heros.herolist.herolist
console.log(herolist)
return (
<>
mall--王者荣耀英雄
{herolist&&herolist.map((item:any,index:number)=>{
return(
- {item.cname}{'->'}{item.title}
)
})}
</>
);
}
export default connect(({ heros }: any) => ({ heros }))(HeroMall)
之后引入个Table做好看一点
import React, { useEffect } from ‘react’;
// import { getHeroList } from ‘…/…/services/heros’
import { connect, Dispatch } from ‘umi’
import { Table, Tag } from ‘antd’;
const HeroMall = (props: any) => {
console.log(props)
useEffect(() => {
let { dispatch } = props
dispatch({
type: ‘heros/fetchHeroList’,
})//触发model中的effect,带上命名空间
}, [])
// fetch(‘/api/herolist’).then(res=>{
// //console.log(res)
// return res.json()
// }).then(res=>{
// console.log(res)
// })
// fetch(‘/api/heros’).then(res=>{
// //console.log(res)
// return res.json()
// }).then(res=>{
// console.log(res)
// })
// getHeroList().then((res)=>{
// console.log(res)
// })
let { heros } = props
let herolist = heros && heros.herolist && heros.herolist.herolist
console.log(herolist)
// ename: 105
// cname: “廉颇”
// title: “正义爆轰”
// new_type: 0
// hero_type: 3
// skin_name: “正义爆轰|地狱岩魂”
const columns = [
{
title: ‘Id’,
dataIndex: ‘ename’,
key: ‘ename’,
render: text => {text},
},
{
title: ‘英雄’,
dataIndex: ‘cname’,
key: ‘cname’,
},
{
title: ‘皮肤’,
dataIndex: ‘title’,
key: ‘title’,
},
{
title: ‘Tags’,
key: ‘skin_name’,
dataIndex: ‘skin_name’,
render: (tags:string) => (
<>
{tags&&tags.split(‘|’).map(tag => {
let color = tag.length > 3 ? ‘geekblue’ : ‘green’;
return (
{tag}
);
})}
</>
),
},
];
return (
<>
mall--王者荣耀英雄
{/*
{herolist && herolist.map((item: any, index: number) => {
return (
- {item.cname}{'->'}{item.title}
)
})}
*/}</>
);
}
export default connect(({ heros }: any) => ({ heros }))(HeroMall)
页面内数据管理
在页面文件夹下面使用_mock.ts、model.ts、services.ts就可以了 建立方法和全局一样,路径要自己配置
import React, { useEffect } from ‘react’; // import { getHeroList } from ‘…/…/services/heros’
import { connect, Dispatch } from ‘umi’;
import { Table, Tag } from ‘antd’;
import HeroTableSearch from ‘./HeroTableSearch’;
const HeroMall = (props: any) => {
console.log(props);
useEffect(() => {
let { dispatch } = props;
dispatch({
type: ‘mall/fetchHeroList’,
}); //触发model中的effect,带上命名空间
}, []); // fetch(‘/api/herolist’).then(res=>{
// //console.log(res)
// return res.json()
// }).then(res=>{
// console.log(res)
// })
// fetch(‘/api/heros’).then(res=>{
// //console.log(res)
// return res.json()
// }).then(res=>{
// console.log(res)
// })
// getHeroList().then((res)=>{
// console.log(res)
// })
let { mall } = props;
let herolist = mall && mall.herolist && mall.herolist.herolist;
console.log(herolist); // ename: 105
// cname: “廉颇”
// title: “正义爆轰”
// new_type: 0
// hero_type: 3
// skin_name: “正义爆轰|地狱岩魂”
const columns = [
{
title: ‘Id’,
dataIndex: ‘ename’,
key: ‘ename’,
render: text => {text},
},
{
title: ‘英雄’,
dataIndex: ‘cname’,
key: ‘cname’,
},
{
title: ‘皮肤’,
dataIndex: ‘title’,
key: ‘title’,
},
{
title: ‘Tags’,
key: ‘skin_name’,
dataIndex: ‘skin_name’,
render: (tags: string) => (
<>
{tags &&
tags.split(‘|’).map(tag => {
let color = tag.length > 3 ? ‘geekblue’ : ‘green’;
return (
{tag}
);
})}
</>
),
},
];
return (
<>
mall--王者荣耀英雄
{/*
{herolist && herolist.map((item: any, index: number) => {
return (
- {item.cname}{'->'}{item.title}
)
})}
*/}</>
);
};
export default connect(({ mall }: any) => ({
mall,
}))(HeroMall);
顺便修改connect
加个搜索功能
用umi的控制加个高级搜索
表单组件代码修改
import styles from “./index.less”;
import React, { useState } from “react”;
import { Form, Row, Col, Input, Button } from “antd”;
import { DownOutlined, UpOutlined } from “@ant-design/icons”;
const AdvancedSearchForm = () => {
const [form] = Form.useForm();
const getFields = () => {
const children = [];
children.push(
(
<Form.Item
name=“hero”
label=‘英雄’
rules={[{
required:true,
message:‘Input something!’
}
]}
</Form.Item>
)
)
children.push(
(
<Form.Item
name=“skin”
label=‘皮肤’
rules={[{
required:true,
message:‘Input something!’
}
]}
</Form.Item>
)
)
return children;
};
const onFinish = (values:any) => {
console.log("Received values of form: ", values);
};
return (
form={form}
name=“advanced_search”
className=“ant-advanced-search-form”
onFinish={onFinish}
{getFields()}
Search
<Button
style={{ marginLeft: 8 }}
onClick={() => {
form.resetFields();
}}
Clear
);
};
export default () => (
{/*
Search Result List*/});
把搜索功能完善
组件
import styles from “./index.less”;
import React, { useState } from “react”;
import { Form, Row, Col, Input, Button } from “antd”;
import { connect, Dispatch } from ‘umi’;
// import {getHeroListBySearch} from ‘…/service’
const AdvancedSearchForm = (props:any) => {
const [form] = Form.useForm();
const getFields = () => {
const children = [];
children.push(
(
<Form.Item
name=“hero”
label=‘英雄’
// rules={[{
// required:true,
// message:‘Input something!’
// }
//]}
</Form.Item>
)
)
children.push(
(
<Form.Item
name=“skin”
label=‘皮肤’
// rules={[{
// required:true,
// message:‘Input something!’
// }
// ]}
</Form.Item>
)
)
return children;
};
const onFinish = async(values:any) => {
console.log("Received values of form: ", values);
props.dispatch({
type: ‘mall/getHeroListBySearch’,
payload:values,
})
};
return (
form={form}
name=“advanced_search”
className=“ant-advanced-search-form”
onFinish={onFinish}
{getFields()}
Search
<Button
style={{ marginLeft: 8 }}
onClick={() => {
form.resetFields();
}}
Clear
);
};
export default connect((mall:any)=>({mall}))((props:any) =>(
{/*
Search Result List*/} ));
模型
import {Effect,Reducer} from ‘umi’
import{getHeroList,getHeroListBySearch}from ‘./service’
const HerosModel:any={
//命名空间
namespace:‘mall’,
//状态
state:{
herolist:[],
},
effects:{
*fetchHeroList(_,{call,put}:any){
const res= yield call(getHeroList)
//console.log(res)
yield put({
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip1024c (备注前端)
总结
阿里十分注重你对源码的理解,对你所学,所用东西的理解,对项目的理解。
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
片转存中…(img-b0TkYDzn-1712698138779)]
[外链图片转存中…(img-xBGT4wAF-1712698138779)]
[外链图片转存中…(img-UYyhiu7l-1712698138779)]
[外链图片转存中…(img-xxYaq1ev-1712698138780)]
[外链图片转存中…(img-L9McHNoZ-1712698138780)]既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip1024c (备注前端)
[外链图片转存中…(img-vNgRKHkB-1712698138780)]总结
阿里十分注重你对源码的理解,对你所学,所用东西的理解,对项目的理解。
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
[外链图片转存中…(img-t3RAnDMI-1712698138781)]