关于加载更多 list 的问题
来源:8-8 实现加载更多功能
weixin_慕神1362405
2020-12-31
immutable 好像对第二个 json 文件没起作用。点击更多内容后报错 item.get is not a function.
// actionCreators.js
import axios from ‘axios’;
import *as constants from ‘./constants’;
import { fromJS } from ‘immutable’;
const changeHomeData = (result) => ({
type: constants.CHANGE_HOME_DATA,
topicList: result.topicList,
articalList: result.articalList,
recommendList: result.recommendList
})
const addHomeList = (list) => ({
type: constants.ADD_HOME_DATA,
list: fromJS(list)
})
export const getHomeInfo = () => {
return (dispatch) => {
axios.get(’/api/home.json’).then((res) => {
const result = res.data.data;
dispatch(changeHomeData(result));
})
}
}
export const getMoreList = () => {
return (dispatch) => {
console.log(‘click’)
axios.get(’/api/homelist.json’).then((res) => {
const result = res.data.data;
// console.log(result);
dispatch(addHomeList(result));
})
}
}
-------------------------
// list.js
class List extends Component {
render() {
const { list, getMoreList } = this.props;
return (
{
list.map((item) => (
<ListItem key={item.get(‘id’)}>
<img
alt=""
className="pic"
src={item.get(‘imgUrl’)}
/>
{item.get(‘title’)}
{item.get(‘desc’)}
))
}
更多内容
)
}
}
// 报错提示
1回答
-
Dell
2021-01-02
你在render里面,先打印一下list,看下结果
122021-01-03
相似问题