会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132553个问题
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:基于SpringSecurity实现后台登录功能 28098楼
JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧) 28099楼
Python 全系列/第一阶段:Python入门/函数和内存分析 28101楼
Python 全系列/第二十三阶段:人工智能基础_机器学习理论和实战(旧)/Softmax回归 28102楼
Python 全系列/第二十三阶段:人工智能基础_机器学习理论和实战(旧)/Softmax回归 28104楼
WEB前端全系列/第七阶段:ECMAScript6新特性模块/ES6第二部分 28105楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/Flask高级 28106楼

//fetch和动态渲染

import React from 'react'

export default class Fetch extends React.Component{

    constructor(props){

        super(props)

        this.state={

            list:''//初始化list的值

        }

    }

    //动态渲染

    componentDidMount(){

        fetch('http://iwenwiki.com/api/blueberrypai/getIndexMovement.php')

        .then(src=>src.json())

        .then(data=>{

            this.setState({

                list:data

            })

            console.log(data);

            console.log(this.state.list.movement[0].title);

            

        })

    }

//     模拟get

//    get(){

//         fetch('http://iwenwiki.com/api/blueberrypai/getBlueBerryJamInfo.php',{data:'参数'})//第二个参数可以传参

//         .then(src=>src.json())

//         .then(data=>{console.log(data)})

//     }


//     模拟post

//     post(){

//         fetch('http://iwenwiki.com/api/blueberrypai/getBlueBerryJamInfo.php',{

//             method:'POST',

//             body:"msg_code:10000&userid:aays",//fetch接收的参数,必须是字符串类型

//             headers:new Headers({//请求头

//                 'Accept':'application/json,text/plain,*/*',//访问权限

//                 'Content-Type':'application/json'//内容类型

//             }),

//         })

//         .then(src=>src.json())

// .then(data=>{console.log(data);})

//     }


    render(){

        // const {list}=this.state//即调用list的时候自动变成this.state.list

    return(

        <div>

            

            {/* <button onClick={this.get}>Fectch用get获取数据</button>

        <button onClick={this.post}>Fetch用post获取数据</button> */}

{

this.state.list.movement.map((element,index)=>{

    return(

        <ul>

            <li>element.title</li>

            <li></li>

            <li></li>

        </ul>

    )

})

}

        </div>

    )

}

}

image.png

WEB前端全系列/第十四阶段:React知识体系/React基础知识 28107楼
JAVA 全系列/第一阶段:JAVA 快速入门/飞机大战小项目训练 28108楼
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:使用SpringCache+Redis实现门户导航缓存 28110楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637