react发送fetch请求get和post


import React from 'react';
import qs from 'querystring'
import api from './api'
export default class App extends React.Component {
  
  constructor(props){
    super(props);
  }

  componentDidMount(){
    // fetch('http://iwenwiki.com/api/blueberrypai/getChengpinInfo.php')
    //   .then(res =>{
    //     return res.json()
    //   })
    //   .then(data =>{
    //     console.log(data)
    //   })


    //   fetch('http://iwenwiki.com/api/blueberrypai/login.php',{
    //     method:'POST',
    //     headers:{
    //         'Content-Type':'application/x-www-form-urlencoded',
    //         "Accept":'application/json,text/plain,*/*'
    //     },
    //     body:qs.stringify(
    //       {
    //         user_id:'[email protected]',
    //         password:'iwen123',
    //         verification_code:'crfvw'
    //       }
    //     )
    //   }).then(res => res.json())
    //   .then(data =>{
    //     console.log(data)
    //   })

    api.getChengpin().then(res => res.json()).then(data => {
      console.log(data)
    }) ;
    api.getLogin({
              user_id:'[email protected]',
              password:'iwen123',
              verification_code:'crfvw'
            }).then(res => res.json()).then(data => {
              console.log(data)
            })

  }

    

  render(){
    return (
      
hello
); } }

 

你可能感兴趣的:(学习笔记)