一、環境依賴版本
1、npm安裝yarn
npm install -g yarn
查看版本:
yarn --version
安裝axios
npm install axios --save-dev
二、腳手架搭建以及在項目中引用antd插件

三、請求數據
代碼如下:
import React from 'react'; import { Link } from 'react-router-dom'; import { Button } from 'antd'; import Axios from 'axios'; function Login() { return ( <div> Login頁面 <ul> <li><Link to="/">顯示1</Link></li> <li><Link to="/home">顯示2</Link></li> </ul> <Button onClick={Fromclick} type="primary">Button</Button> </div> ); } function Fromclick() { //發送請求 Axios.get("http://wthrcdn.etouch.cn/weather_mini?citykey=101010100") .then(res => { console.log("請求成功:", res.data); }) .catch(err => { window.console.log('請求失敗:', err); }) } export default Login;
