Weibozzz/next-blog

翻页获取 this.state.currentPage 总是1

Closed this issue · 2 comments

componentWillMount() {
console.log("componentWillMount")
console.log("componentWillMount"+this.state.currentPage)

const {dispatch} = this.props;
const queryTotalString = {
  type: 'hot',

};
getHotArticleList(dispatch, getBlogUrl(queryTotalString))
getViewList(dispatch, getViewUrl())
getCreateTimeList(dispatch, getCreateTimeUrl())

}

async componentDidMount() {
console.log("componentDidMount")
const {router = {}} = Router
const {query = {}} = router
const {id = '1'} = query
this.setState({
currentPage: Number(id)
})

const {dispatch} = this.props;
const realIp = await real_ip()
let queryParamsObj = {real_ip: realIp, ip: returnCitySN['cip'], address: returnCitySN['cname']};
//存取用户ip
postSaveIp(dispatch, postSaveIpUrl(), queryParamsObj)

}

可你的服务器是怎么分的页呢,我现在加载的总是第一页的数据

入口文件server.js配置了吗?getInitialProps方法来请求数据进行渲染,达到服务端渲染的目的,请仔细查看我的源码剖析部分