运用到的技术
dvaJS
antd Design
./model/nyltest/index.js
import { get } from 'api';
export default {
namespace: 'nyltest',
state: {
nylName: 'nielonglong',
nylAge: 22,
current2: 1,
total2: 0,
searchParams: {},
recipeList: [],
totalData: {},
},
effects: {
*getRecipeData_nyl({ payload }, {call, put, select}) {
const { searchParams } = yield select(state => state.testnyl);
const data = yield call(get, '接口url', { ...searchParams, ...payload });
yield put({
type:'save',
payload:{
recipeList: data.items,
current2: payload.page,
total2: data.count,
},
});
}
},
reducers: {
save(state, { payload }) {
console.log({...state, ...payload})
return {...state, ...payload}
}
},
};
./routes/Nyltest/index.js
import React, { Component } from 'react';
import { connect } from 'dva';
import { columns1, columns2 } from './colums';
import styles from './index.less';
import { Tabs, Button, Card, Row, Col, Table, Input, DatePicker } from 'antd';
const TabPane = Tabs.TabPane;
@connect((state) => ({
nyltestData: state.nyltest,
}))
export default class Nyltest extends Component{
constructor(props) {
super(props)
this.requestData()
}
componentDidMount() {
let p1 = {name: '张三'}
let p2 = {age: '男'}
console.log({...p1, ...p2})
}
requestData = (page = 1, per = 3) => {
console.log('page='+ page, 'per=' + per)
this.props.dispatch({
type:'nyltest/getRecipeData_nyl',
payload: {
page,
per
},
});
};
pageFunc = (p, p2) => {
console.log('p='+p+'p2='+p2)
}
render() {
const { nyltestData } = this.props
const { nylName, nylAge, recipeList, current2, total2 } = nyltestData;
return (
<div style={{background: '#fff'}}>
<h4>{nylName}</h4>
<h4>{nylAge}</h4>
<Tabs defaultActiveKey='1'>
<TabPane tab='栏目1' key='1'>
<div>chufang</div>
</TabPane>
<TabPane tab='栏目2' key='2'>
<div>
<Table columns={columns2}
dataSource={ recipeList }
pagination={{ current:current2, total: total2, pageSize: 3, onChange: this.requestData }}
/>
</div>
</TabPane>
</Tabs>
</div>
)
}
}