先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7
深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Web前端全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上前端开发知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
如果你需要这些资料,可以添加V获取:vip1024c (备注前端)
正文
store/actionType.js
export const CHANGE_INPUT_VALUE = ‘change_input_value’
export const ADD_TODO_ITEM = ‘add_todo_item’
export const DELETE_TODO_ITEM = ‘delete_todo_item’
核心API:
-
createStore 创建store
-
store.dispatch 派发action,把数据上传到Store中
-
store.getState 获取store中所有的数据内容,但是Store中的数据发生变化时,组件不会知道
-
store.subscribe 监听Store中的数据变化,Store中的数据一旦发生变化,该方法就会被执行
第一步 安装redux-thunk中间件
npm install redux-thunk
第二步 在store中引入thunk组件
import {createStore,applyMiddleware } from ‘redux’;
import Reducer from ‘./Reducer’;
import thunk from ‘redux-thunk’;
const store = createStore(Reducer,applyMiddleware(thunk));
export default store;
第三步 封装异步请求方法
在TodoList.js组件中,封装异步获取请求的方法:
import React, { Component } from ‘react’
import Store from ‘./Store’
import axios from ‘axios’
export class TodoList extends Component {
constructor(props){
super(props);
this.state = Store.getState();
this.handleStoreChange = this.handleStoreChange.bind(this);
Store.subscribe(this.handleStoreChange);
}
//在生命周期函数中调用异步方法
componentDidMount(){
Store.dispatch(this.getTodoListDatas());
}
//异步获取请求的方法
getTodoListDatas(){
return (dispatch)=>{
axios.get(“/data.json”)
.then(resp => {
const action = {
type:‘axios_getdata’,
data:resp.data
}
dispatch(action)
})
}
}
handleStoreChange(){
this.setState(Store.getState());
}
render() {
return (
添加
{this.state.list.map((item,index)=>{
return (
- {item}
);
})}
)
}
}
export default TodoList
第四步 在reducer中接收action信息
const defaultState = {
inputValue:‘’,
list:[]
}
export default (state = defaultState,action) => {
if(action.type === ‘axios_getdata’){
const newState = state;
newState.list = action.data;
return newState;
}
return state
}
redux-thunk这个中间件可以使我们把这样的异步请求或者说复杂的逻辑可以放到action里面去处理,redux-thunk使redux的一个中间件,为什么叫做中间件
我们说中间件,那么肯定是谁和谁的中间,那么redux的中间件指的是谁和谁的中间呢?
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Xpoa4tw8-1627045469637)(C:\Users\mac\AppData\Roaming\Typora\typora-user-images\1581401374679.png)]
如图。view在redux中会派发一个action,action通过store的dispatch方法派发给store,store接收到action,连同之前到state,一起传给reducer,reducer返回一个新到数据给store,store去改变自己到state。这是redux的一个标准流程,那么我们说redux的中间件指的是谁和谁的之间,大家一定要记住,**redux的中间件指的是action和store之间。之前我们说action只能是一个对象,所以action是一个对象直接派发给了store。**但是现在,当我们使用了redux-thunk之后,action可以是函数了。
为什么可以是函数呢,看这张图。action通过dispatch方法被传递给store,那么action和store之间是谁,是不是就是dispatch这个方法,**实际上我们指的中间件指的是什么呢,就是对dispatch方法的一个封装,或者说是dispatch方法的一个升级,最原始的dispatch方法,他接收到一个对象之后,会把这个对象传递给store,这就是view中间件的一个情况。**当我们对dispath做了一个升级之后,比如说我们使用了redux-thunk这个中间件,对dispath做了一个升级,这个时候当你调用dispatch方法,给dispatch传递的参数是一个对象的话,那么这个dispatch就会把这个对象直接传给store。跟之前写一个对象,调用dispatch传给store没有任何的区别。但是这个时候假设传给dispatch方法是一个函数的话,这个时候dispatch方法已经升级了。他知道如果你传递过来是一个函数的话,他就不会把这个函数直接传递给store。他会怎么办呢?
他会让你这个函数先执行,然后执行完了之后,需要调用store的时候,这个函数再去调用store。所以dispatch做了一个事情,他会根据参数的不同,执行不同的事情,如果你参数是对象,那我直接传给store。如果你参数是函数,那就把这个函数执行结束。所以讲到这大家应该知道
**redux中间件,他的原理是非常简单的,他就是对store对dispatch方法做一个升级,之前这个dispatch方法只能接收一个对象,现在升级之后,就可以接收对象,也可以接收函数了。**当然这里用什么对他进行一个升级呢?用redux-thunk对他进行了升级。当然中间件不只redux-thunk这一个,实际上redux中间件非常多,比如说我们说的redux-log,可以记录action每次派发的日志,那他怎么记录呢?其实也很简单,每次调用 action的时候,都会通过dispatch把这个action传递给store,那么我可以对dispatch做一个升级,dispatch不仅仅把action传递给store,而且在每次传递之前呢,还通过console.log,把这个action打印出来。这样就写了一个redux-log的中间件。他可以在每次派发action的时候,把这个action打印在控制台里面。
最近用的比较火的redux中间件,除了redux-thunk,redux-log这样的东西,还有一个中间件,叫做redux-saga。他的应用范围也非常广,redux-saga也是解决redux中间异步问题的中间件。不同于redux-thunk。redux-thunk是把异步操作放在action里面操作。而redux-saga采用的设计思想是,单独的把一个异步逻辑拆分出来,放在一个异步文件里面管理,基本上掌握了redux-thunk和redux-saga这两者的设计思路之后呢,再去做redux里面的异步逻辑,或者说复杂的逻辑,如何去拆分,就比较明白了。
第一步 安装react-redux
npm install react-redux
第二步 创建store和reducer
store.js文件
import {createStore } from ‘redux’;
import reducer from ‘./reducer’;
const store = createStore(reducer);
export default store;
reducer.js文件
const defaultState = {
inputValue:‘hello’,
list:[‘a’,‘b’,‘c’]
}
export default (state = defaultState,action) => {
return state
}
第三步 在index.js入口文件引入Provider组件
import React from ‘react’;
import ReactDOM from ‘react-dom’;
import TodoList from ‘./reactredux/TodoList’
import {Provider} from ‘react-redux’
import store from ‘./reactredux/store’
const APP = (
);
ReactDOM.render(APP , document.getElementById(‘root’));
第四步 在TodoList.js组件中引入connect组件
import React, { Component } from ‘react’
import {connect} from ‘react-redux’
export class TodoList extends Component {
render() {
return (
添加
{this.props.list.map((item,index)=>{
return (
- {item}
);
})}
)
}
}
const mapStateToProps = (state) =>{
return {
inputValue: state.inputValue,
list:state.list
}
}
const mapDispatchToProps = (dispatch) =>{
return {
changeInputValue(e){
const action = {
type:“change_inputvalue”,
inputValue:e.target.value
}
dispatch(action);
},
addClick(){
const action = {
type:“add_list”,
value:this.props.inputValue
}
dispatch(action);
}
}
}
export default connect(mapStateToProps,mapDispatchToProps)(TodoList);
第五步 在reducer中接收action的值
const defaultState = {
inputValue:‘hello’,
list:[‘a’,‘b’,‘c’]
}
export default (state = defaultState,action) => {
if(action.type === ‘change_inputvalue’){
const newState = JSON.parse(JSON.stringify(state));
newState.inputValue = action.inputValue;
return newState;
}
if(action.type === ‘add_list’){
const newState = JSON.parse(JSON.stringify(state));
newState.list.push(action.value);
newState.inputValue = “”;
return newState;
}
return state
}
安装依赖
cnpm i redux-persist --save
7.1、基本用法
示例代码:
const { browserHistory } = require(‘react-router’);
const { syncHistoryWithStore, routerReducer } = require(‘react-router-redux’);
const { createStore, combineReducers } = require(‘redux’);
const { student,school } = require(‘./reducers’);
// 只要用上 persistStore 和 autoRehydrate 就行啦
const { persistStore, autoRehydrate } = require(‘redux-persist’);
// 存储机制,可换成cookie等其他机制
const { asyncSessionStorage } = require(‘redux-persist/storages’);
const initialState = {
student: {
age: 21,
sex: “female”,
},
school:{
name: “蓝翔大学”
}
};
const reducers = combineReducers({
student,
school,
routing: routerReducer,
});
// autoRehydrate作为参数传入redux的createStore方法
const store = createStore(
reducers,
initialState,
autoRehydrate(),
);
// persistStore的使用,可配置很多参数,如存储引擎、黑白名单等。
persistStore(
store,
{
storage: asyncSessionStorage,
blacklist: [
‘routing’,
‘school’ // school reducer 的数据不进行持久化
],
},
);
const history = syncHistoryWithStore(browserHistory, store);
module.exports = {
store,
history,
};
7.2、整合react-redux
store/index.js
文件代码:import { createStore, applyMiddleware, compose } from ‘redux’;
import reducers from ‘./reducers’;
import thunk from ‘redux-thunk’;
import { persistStore, persistReducer } from ‘redux-persist’;
import storage from ‘redux-persist/lib/storage’;
// 存储对象,默认存储到localstorage
const persistConfig = {
key: ‘root’,
storage,
}
// 重新组装reducer
const persistedReducer = persistReducer(persistConfig, reducers)
// redux调试工具配置代码
const composeEnhancers =
typeof window === ‘object’ &&
window.REDUX_DEVTOOLS_EXTENSION_COMPOSE ?
window.REDUX_DEVTOOLS_EXTENSION_COMPOSE({}) : compose;
const enhancer = composeEnhancers(
applyMiddleware(thunk),
数据结构与算法
这一块在笔试、面试的代码题中考核较多,其中常考的数据结构主要有:数组、链表、队列、栈、Set、Map、哈希表等,不同数据结构有不同的方法以及储存原理,这些算是技术岗的必备知识。算法部分主要分为两大块,排序算法与一些其他算法题。
排序算法根据考频高低主要有:快速排序、归并排序、堆排序、冒泡排序、插入排序、选择排序、希尔排序、桶排序、基数排序、Timsort这十种,这类考核点要么是算法的时间、空间复杂度、稳定度,要么是直接手写代码,故在理解算法原理的同时,对JS语言版的排序算法代码也要加强记忆。
- 二叉树层序遍历
- B 树的特性,B 树和 B+树的区别
- 尾递归
- 如何写一个大数阶乘?递归的方法会出现什么问题?
- 把多维数组变成一维数组的方法
- 知道的排序算法 说一下冒泡快排的原理
- Heap 排序方法的原理?复杂度?
- 几种常见的排序算法,手写
- 数组的去重,尽可能写出多个方法
- 如果有一个大的数组,都是整型,怎么找出最大的前 10 个数
- 知道数据结构里面的常见的数据结构
- 找出数组中第 k 大的数组出现多少次,比如数组【1,2, 4,4,3,5】第二大的数字是 4,出现两次,所以返回 2
- 合并两个有序数组
- 给一个数,去一个已经排好序的数组中寻找这个数的位 置(通过快速查找,二分查找)
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注前端)
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
识。算法部分主要分为两大块,排序算法与一些其他算法题。排序算法根据考频高低主要有:快速排序、归并排序、堆排序、冒泡排序、插入排序、选择排序、希尔排序、桶排序、基数排序、Timsort这十种,这类考核点要么是算法的时间、空间复杂度、稳定度,要么是直接手写代码,故在理解算法原理的同时,对JS语言版的排序算法代码也要加强记忆。
- 二叉树层序遍历
- B 树的特性,B 树和 B+树的区别
- 尾递归
- 如何写一个大数阶乘?递归的方法会出现什么问题?
- 把多维数组变成一维数组的方法
- 知道的排序算法 说一下冒泡快排的原理
- Heap 排序方法的原理?复杂度?
- 几种常见的排序算法,手写
- 数组的去重,尽可能写出多个方法
- 如果有一个大的数组,都是整型,怎么找出最大的前 10 个数
- 知道数据结构里面的常见的数据结构
- 找出数组中第 k 大的数组出现多少次,比如数组【1,2, 4,4,3,5】第二大的数字是 4,出现两次,所以返回 2
- 合并两个有序数组
- 给一个数,去一个已经排好序的数组中寻找这个数的位 置(通过快速查找,二分查找)
[外链图片转存中…(img-HNC1HLWb-1713186149610)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注前端)
[外链图片转存中…(img-4rPvYGFL-1713186149611)]一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!