內(nèi)容:網(wǎng)絡(luò)請求、UI庫
一、網(wǎng)絡(luò)請求
配置代理
在項目根目錄的package.json的第一層配置選項中增加一行
"proxy":"目標(biāo)域名地址[:端口號]"
在頁面中發(fā)起網(wǎng)絡(luò)請求時,不需要寫要請求的接口域名,直接寫請求地址即可。
注意:一定要重啟react項目
1.jquery
(1)安裝
npm install jquery --save
(2)引用
import $ from 'jquery'
(3)使用
$.ajax({
url:'要請求的地址(不包含域名和端口號)',
success:function(){
}
})
2.axios
(1)安裝
npm i axios --save
(2)引用
import axios from 'axios'
(3)使用
axios({
url:'/api/userlist'
}).then(res=>{
this.setState({
users:res.data.data
})
})
3.fetch
fetch它不需要安裝
fetch('請求地址',[配置選項]).then(獲取響應(yīng),要對響應(yīng)進(jìn)行JSON處理).then(獲取JSON處理之后的數(shù)據(jù))
get請求:
fetch('請求地址').then(res=>res.json()).then(resJson=>{...})
post請求:
fetch('請求地址',{
method:'post',
headers:{
'Content-Type':'application/json'
},
body:JSON.stringify({key:value})
})
二、UI庫
ant-design
1.安裝
npm install antd --save
2.引入樣式
src/App.js
import 'antd/dist/antd.css';
三、作業(yè)
使用antd進(jìn)行后臺頁面布局,做管理員管理、輪播圖管理功能。