调取接口
- 增
- 删
- 改
- 查
增
对接口的数据添加字段
url: urlData.filter((urlItem) => urlItem.id === item.id),
url: urlData.find((urlItem) => urlItem.id === item.id)
//理想,不能实现
url: urlData.find((urlItem) => {if (urlItem.id === item.id) {return urlItem.url;}}),
//实际,能够实现
url: urlData.find((urlItem) => urlItem.id === item.id)?.url //可以更改?.url='自定义url'
url: urlData.filter((urlItem) => urlItem.id === item.id),
*getSkyInfoServerFourNumList({ payload }, { call, put }) {const response = yield call(getSkyInfoServerFourNumList, payload);// console.log('response getSkyInfoServerFourNumList>>>', response);if (response.code === 200) {const resDataLists = response.data;const urlData = [{id: 1,url: '/digitalTransportation',},{id: 2,url: '/digitalAgriculture',},{id: 3,url: '/digitalPipeNetwork',},{id: 4,url: '/digitalBattlefield',},];const myAddData = resDataLists.map((item, index) => {return {...item,url: urlData.find((urlItem) => urlItem.id === item.id)?.url,};});// console.log('response resDataLists>>>', myAddData);yield put({type: 'setState',payload: { skyInfoServerFourNumList: myAddData },});} else {notification.warning({message: '后端接口没有返回数据或数据不存在',description: response.msg,});}},
删
改
*getCompanyList({ payload }, { call, put }) {const response = yield call(getCompanyList, payload);if (response.code === 200) {const resDataLists = response.data;const myModifyData = resDataLists.map((item) => {return {...item,address: item.address.split('***'),content: item.content.split('***'),};});yield put({type: 'setState',payload: { conpanyIntroduce: myModifyData },});} else {notification.warning({message: '后端接口没有返回数据或数据不存在',description: response.msg,});}},