
redux
Passion is Energy
这个作者很懒,什么都没留下…
展开
-
为什么不在 constructor或者 componentWillMount 请求数据?
为什么不在 constructor?官网说明,在 concurrent 模式下, constructor 会被执行多次!constructor 是用于初始化 class 的初始状态,不建议有副作用的逻辑在里面!面向对象里, class 的 constructor 是用于存放一些具有确定性的属性和方法!为什么不在 componentWillMount?如果服务端渲染,componentWillMount 会被服务端渲染一次,前端渲染一次。componentWillMount 这个生命函数钩子在原创 2021-10-10 19:13:27 · 624 阅读 · 0 评论 -
为什么token要存在localstorage,然后通过redux/vuex去获取?
一.两个原因:localStorage:优点: 持久,能够永久存储的缺点: 不是响应式的vuex / redux优点: 响应式的缺点: 不持久,存储在内存中,刷新就会丢失。原创 2021-09-10 19:58:19 · 1045 阅读 · 0 评论 -
store.subscribe需要先定义,后执行;可以定义多次 subscribe
1. codeimport { createStore } from "redux";const reducer = (state = 0, action) => { switch (action.type) { case "add": return state + 1; default: return state; }};const store = createStore(reducer);console.log(store);s原创 2021-09-08 11:41:10 · 2316 阅读 · 0 评论 -
redux 流程分析
Redux is a predictable state container for JavaScript apps.It helps you write applications that behave consistently, run in different environments (client, server, and native), and are easy to test. On top of that, it provides a great developer experienc原创 2021-09-04 23:19:45 · 177 阅读 · 0 评论