|
@@ -1,17 +1,23 @@
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
// useSelector 读数据 你选择的state片段 useSelector()
|
|
// useSelector 读数据 你选择的state片段 useSelector()
|
|
|
import { addOne, asyncAddThing } from "../store/slices/counterSlice";
|
|
import { addOne, asyncAddThing } from "../store/slices/counterSlice";
|
|
|
|
|
+
|
|
|
function CountPage() {
|
|
function CountPage() {
|
|
|
const { value } = useSelector(x => x.counterSlice);
|
|
const { value } = useSelector(x => x.counterSlice);
|
|
|
|
|
+ const { token } = useSelector(x => x.userInfoSlice)
|
|
|
|
|
+ console.log(token)
|
|
|
const dispatch = useDispatch();
|
|
const dispatch = useDispatch();
|
|
|
// useDispatch 写数据 触发函数
|
|
// useDispatch 写数据 触发函数
|
|
|
console.log(dispatch, 'dd')
|
|
console.log(dispatch, 'dd')
|
|
|
return (
|
|
return (
|
|
|
<div>
|
|
<div>
|
|
|
|
|
+ <h1>展示token:{token}</h1>
|
|
|
|
|
+ <button onClick={() => localStorage.setItem('token1', Date.now())}>添加token</button>
|
|
|
<h1>计数器</h1>
|
|
<h1>计数器</h1>
|
|
|
<h2>初始值:{value}</h2>
|
|
<h2>初始值:{value}</h2>
|
|
|
<button onClick={() => dispatch(addOne(10))}>加一</button>
|
|
<button onClick={() => dispatch(addOne(10))}>加一</button>
|
|
|
- <button onClick={() => dispatch(asyncAddThing)}>延迟2s加一</button>
|
|
|
|
|
|
|
+ <button onClick={() => dispatch(asyncAddThing(5))}>延迟2s加一</button>
|
|
|
|
|
+ <button>添加用户信息</button>
|
|
|
</div>
|
|
</div>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|