- 使用hooks可以帮助我们在函数式组件中实现类似于class类组件中的state,生命周期的效果
- hooks针对于函数式组件来使用的,不能在class类组件中使用,不能在普通函数中使用hooks,但是可以在以use开头的函数中使用hooks,react会将其认为是自定义hook
- 类组件中使用hooks方式可以自定义高阶函数中使用hooks
- 只能在函数最外层调用 Hook。不要在循环、条件判断或者子函数中调用
2023/7/7大约 20 分钟
npm install react-router-dom
定义的状态用于管理数据
通过派发actions修改store中的数据,action是一个普通的JavaScript对象,用来描述这次更新的type和content
github地址:https://github.com/bvaughn/react-virtualized
使用命令:
npm install react-virtualized --save
const getAwardStudentTemplate = () => {
exportAwardStudentsList({}).then((res) => {
if (res.data.Data !== null) {
const a = document.createElement('a') // a标签导出下载
a.href = res.data.Data.DownloadUrl
a.click()
a.remove()
}
})
getImportFileTemplate({ params: { TabName: 'AwardA' } }).then((res) => {
if (res.data.Data !== null) {
let downloadUrl2 = res.data.Data.DownloadUrl
let iframe = document.createElement('iframe') // iframe导出下载
iframe.id = 'iframe2'
iframe.style.display = 'none'
document.body.appendChild(iframe)
iframe.src = downloadUrl2
}
})
}
import React, { useState } from "react";
export default function HookState() {
// useState传入一个默认值将赋值给返回数组中的第一个数,第二个数为函数,可针对该数进行专门的赋值
const [count, setCount] = useState(0);
return (
<div>
<h3>当前计数:{count}</h3>
<button
onClick={(e) => {
setCount(count + 1);
}}
>
+1
</button>
<button
onClick={(e) => {
setCount(count - 1);
}}
>
-1
</button>
</div>
);
}
axios是目前前端使用非常广泛的网络请求库,包括Vue作者也是推荐在vue中使用axios;
主要特点包括:在浏览器中发送 XMLHttpRequests 请求、在 node.js 中发送 http请求、支持 Promise API、拦截请求和响应、转换请求和响应数据等等;
axios: ajax i/o system.