亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

react state

react state

慕田峪7331174 2019-03-13 17:15:33
想要在render中使用this.state.data 一直報錯import React from 'react'import PureRenderMixin from 'react-addons-pure-render-mixin'import { getListData } from '../../../fetch/home/home'import ListCompoent from '../../../components/List'import LoadMore from '../../../components/LoadMore'import './style.less'class List extends React.Component {    constructor(props, context) {        super(props, context);        this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);        this.state = {            data: [],            hasMore: false,            isLoadingMore: false,            page: 0        }    }    render() {        console.log(this.state)        return (            <div>                <h2 className="home-list-title">猜你喜歡</h2>               {this.state.data}                 {/*  只要添加上面的語句就會報錯 */}            </div>        )    }    componentDidMount() {        // 獲取首頁數據        this.loadFirstPageData()    }    // 獲取首頁數據    loadFirstPageData() {        const cityName = this.props.cityName        const result = getListData(cityName, 0)           // 處理數據        result.then(res => {            return res.json()        }).then(json => {            const hasMore = json.hasMore            const data = json.data            this.setState({                hasMore: hasMore,                // 注意,這里講最新獲取的數據,拼接到原數據之后,使用 concat 函數                data: this.state.data.concat(data)            })        }).catch(ex => {            if (__DEV__) {                console.error('首頁”猜你喜歡“獲取數據報錯, ', ex.message)            }        })    }    }export default Listdebug 看到state中是包含這個屬性的,但是爲什麼不能使用呢?還請指教下。
查看完整描述

2 回答

?
蕪湖不蕪

TA貢獻1796條經驗 獲得超7個贊

this.state.data得是一個元素吧?


查看完整回答
反對 回復 2019-03-22
  • 2 回答
  • 0 關注
  • 542 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號