真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

react如何mock數(shù)據(jù)-創(chuàng)新互聯(lián)

小編給大家分享一下react如何mock數(shù)據(jù),希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!

創(chuàng)新互聯(lián)基于成都重慶香港及美國等地區(qū)分布式IDC機房數(shù)據(jù)中心構(gòu)建的電信大帶寬,聯(lián)通大帶寬,移動大帶寬,多線BGP大帶寬租用,是為眾多客戶提供專業(yè)服務(wù)器托管報價,主機托管價格性價比高,為金融證券行業(yè)綿陽機房托管,ai人工智能服務(wù)器托管提供bgp線路100M獨享,G口帶寬及機柜租用的專業(yè)成都idc公司。

react mock數(shù)據(jù)的方法:首先在public目錄下建立【/api/headerList.json】文件;然后加入相關(guān)代碼【axios.get('/api/headerList.json')】。

react mock數(shù)據(jù)的方法:

如下代碼,在input獲得焦點時調(diào)用getList()方法。

const mapDispathToProps = (dispatch) => {
    return {
        handleInputFocus() {
            dispatch(actionCreators.getList())
        }
    }
}

getList()方法是通過Ajax獲取數(shù)據(jù),此時后端并沒有寫好,所以自己mock一個數(shù)據(jù)。

export const getList = () => {
    return (dispatch) => {
        axios.get('/api/headerList.json').then((res) => {
            const data = res.data;
            console.log(data)
        }).catch(() => {
            console.log('error')
        })
    }
}

axios.get('/api/headerList.json')這句代碼,計算機會首先去src目錄下尋找/api/headerList.json,沒有找到然后去public目錄下找,此時我們在public目錄下建立/api/headerList.json文件,文件如下:

{
    "success":true,
    "data":["微信","支付寶","螞蟻金服","被騙","借唄","詐騙","盜竊","pandas","TensorFlow","PyTorch","Caffe","scikit-learn","Python","Keras","pyecharts","ggplot","Matplotlib","Gensim","Bokeh","Theano","Scrapy","SciPy","Plotly","NumPy","XGBoost","是","他","有","光大永明","我","要","人","Android","女","大","不","著","男","它","二","于","中","java","把","上","這","下","的","了","來"]
}

看完了這篇文章,相信你對react如何mock數(shù)據(jù)有了一定的了解,想了解更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!


網(wǎng)站標(biāo)題:react如何mock數(shù)據(jù)-創(chuàng)新互聯(lián)
當(dāng)前地址:http://weahome.cn/article/gecgc.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部