浅谈redux以及react-redux简单实现


Posted in Javascript onAugust 28, 2018

写在前头

redux 简介

随着 JavaScript 单页应用开发日趋复杂,JavaScript 需要管理比任何时候都要多的 state (状态)。 这些 state 可能包括服务器响应、缓存数据、本地生成尚未持久化到服务器的数据,也包括 UI 状态,如激活的路由,被选中的标签,是否显示加载动效或者分页器等等。

管理不断变化的 state 非常困难。如果一个 model 的变化会引起另一个 model 变化,那么当 view 变化时,就可能引起对应 model 以及另一个 model 的变化,依次地,可能会引起另一个 view 的变化。直至你搞不清楚到底发生了什么。state 在什么时候,由于什么原因,如何变化已然不受控制。 当系统变得错综复杂的时候,想重现问题或者添加新功能就会变得举步维艰。

如果这还不够糟糕,考虑一些来自前端开发领域的新需求,如更新调优、服务端渲染、路由跳转前请求数据等等。前端开发者正在经受前所未有的复杂性,难道就这么放弃了吗?当然不是。

这里的复杂性很大程度上来自于:我们总是将两个难以理清的概念混淆在一起:变化和异步。 如果把二者分开,能做的很好,但混到一起,就变得一团糟。一些库如 React 试图在视图层禁止异步和直接操作 DOM 来解决这个问题。美中不足的是,React 依旧把处理 state 中数据的问题留给了我们自己。而 redux 就可以来帮我管理这些状态;

demo 演示

浅谈redux以及react-redux简单实现

demo 结构树
├── config-overrides.js
├── .gitignore
├── package.json
├── package-lock.json
├── public
│ ├── favicon.ico
│ ├── index.html
│ └── manifest.json
├── README.md
└── src
 ├── App.js
 ├── Demo
 │ ├── actionCreate.js
 │ ├── Demo.jsx
 │ ├── react-redux.js
 │ ├── reducer.js
 │ ├── redux.js
 │ ├── style.css
 │ └── thunk.js
 └── index.js

一、 redux API createStore 的实现

  首先我们先结合 reducer 以及 action 的知识简单实现开头展示的 demo, 并逐步揭晓 createStore 的神秘面纱;

1.1 准备工作:

创建 reducer 并导出 reducer
// reducer.js
const initState = { user: 'qianyin', age: 18, sex: '男' };
export const reducer = (state=initState, action) => {
 switch(action.type){
 case 'USER_UPDATE':
  return {...state, ...action.payload};
 case 'AGE_GROW':
  return {...state, age: state.age + 1};
 case 'SEX_UPDATE':
  return {...state, ...action.payload};
 default:
  return state;
 }
}
创建 action 创建函数
// actionCreate.js
export const changeUser = (user) => {
 return {
 payload:{user},
 type: 'USER_UPDATE',
 };
}

export const changeAge = () => {
 return { type: 'AGE_GROW' };
}
通过 react 在页面上预先绘制出基本的元素
/* style.css */
.btn{
 height: 31px;

}
.input{
 height: 25px;
}
// Demo.jsx
import React from 'react';
import './style.css';

export default class Demo extends React.Component{
 onChange = () => {}
 onClick = () => {}
 render(){
 return (
  <div>
  <p>user: xxx, age: xxx</p>
  user: 
  <input type="text" className="input" onChange={this.onChange}/>
   
  <button className="btn" onClick={this.onClick}>年龄增长</button>
  </div>
 );
 }
}
最终页面将渲染如下:

浅谈redux以及react-redux简单实现

1.2 demo 的初次实现代码

  • 创建全局状态 state;
  • 创建监听队列;
  • 针对监听队列,新增函数用于将指定监听对象添加到队列中;
  • 在函数 dispatch 中执行 reducer 将返回值作为新的 state, 同时依次执行监听对象;
  • 默认执行一次 dispatch 给定一个 type 相对唯一的 action, 目的是为了匹配 reducer 的默认状态值,从而实现对 redux state 的初始化;
  • 在组件 Demo 通过在函数 update 使用 this.setState 将全局 state 保存到 react state 中,并将函数 update 添加到监听队列中;从而使得当我们一旦试图通过 dispatch 修改全局状态时,能够及时更新 react state 最终触发 react 生命周期 render;
  • 在 react 生命周期 componentDidMount 中我们除了将 update 添加到监听队列以外,还需手动执行一次 update 其主要目的就是为了首次初始化 react state;
// Demo.jsx
import React from 'react';
import { changeAge, changeUser } from './actionCreate';
import { reducer } from './reducer';
import './style.css';

let state;
const listeners = [];
const subscribe = (listener) => {
 listeners.push(listener);
}
const dispatch = (action) => {
 state = reducer(state, action);
 console.log(state);
 listeners.forEach(v => v());
}
dispatch({type: '%$&HJKAJJHDJHJ'});

export default class Demo extends React.Component{
 state = {user: 'xxx', age: 'xxx'};
 componentDidMount(){
 subscribe(this.update);
 this.update();
 }

 update = () => {
 this.setState(state);
 }

 onChange = (e) => {
 dispatch(changeUser(e.target.value));
 }

 onClick = () => {
 dispatch(changeAge());
 }

 render(){
 return (
  <div>
  <p>user: {this.state.user}, age: {this.state.age}</p>
  user: 
  <input type="text" className="input" onChange={this.onChange}/>
   
  <button className="btn" onClick={this.onClick}>年龄增长</button>
  </div>
 );
 }
}

1.3 API createStore 的实现

其实上文的代码中对于 createStore 的实现原理已经基本描述清除,下面我们只是单纯的对代码进行了简单的封装;当然为了能够获取到 state 我们专门增加了一个函数 getState 来实现它;

createStore 函数实现
// redux.js

export const createStore = (reducer) => {
 // 声明常量
 let state;
 const listeners = [];

 // 获取状态
 const getState = () => {
 return state;
 }

 // 添加监听对象
 const subscribe = (listener) => {
 listeners.push(listener);
 }

 // [1]执行reducer修改状态 [2]遍历执行监听对象
 const dispatch = (action) => {
 state = reducer(state, action);
 listeners.forEach(v => v());
 }

 // 初始化 state
 dispatch({type: '%$&HJKAJJHDJHJ'});
 
 // 暴露接口
 return {getState, subscribe, dispatch};
}
调用 createStore 并对 demo 进行修改
// Demo.jsx
import React from 'react';
import './style.css';
import { changeAge, changeUser } from './actionCreate';
import { reducer } from './reducer';
import { createStore } from './redux';

const store = createStore(reducer);

export default class Demo extends React.Component{
 state = {user: 'xxx', age: 'xxx'};
 componentDidMount(){
 store.subscribe(this.update);
 this.update();
 }

 update = () => {
 this.setState(store.getState());
 }

 onChange = (e) => {
 store.dispatch(changeUser(e.target.value));
 }

 onClick = () => {
 store.dispatch(changeAge());
 }

 render(){
 return (
  <div>
  <p>user: {this.state.user}, age: {this.state.age}</p>
  user: 
  <input type="text" className="input" onChange={this.onChange}/>
   
  <button className="btn" onClick={this.onClick}>年龄增长</button>
  </div>
 );
 }
}

二、 react-redux API Provider 的实现

在 react 中大多数情况下我们需要将状态传递给后代组件进行使用的,当然通过 props 是可以实现状态从父级到子级的传递,但是当状态需要传递的层级比较深的情况下再使用 props 就显得无力了,那么在 react-redux 中它是如何实现对 store 的传递的呢?

2.1 react context 的引入

在 App.js 中创建 store 并通过 context 传递 store
// App.js
import React, { Component } from 'react';
import propTypes from 'prop-types';
import { createStore } from './Demo/redux';
import { reducer } from './Demo/reducer';
import Demo from './Demo/Demo';

// 创建 store
const store = createStore(reducer);

class App extends Component {
 // 声明 childContextTypes 状态属性类型
 static childContextTypes = {
 store: propTypes.object
 };
 // 设置 childContext
 getChildContext(){
 return {store}
 }
 render() {
 return <Demo />;
 }
}
export default App;
在子组件 Demo 中通过 context 获取 store 并对代码进行简单修改
// Demo.jsx
import React from 'react';
import propTypes from 'prop-types';
import './style.css';
import { changeAge, changeUser } from './actionCreate';

export default class Demo extends React.Component{
 // 设置 context 状态值类型
 static contextTypes = {
 store: propTypes.object
 };

 constructor(props, context){
 super(props, context);
 // 获取store
 this.store = context.store;
 this.state = {user: 'xxx', age: 'xxx'};
 }
 
 componentDidMount(){
 this.store.subscribe(this.update);
 this.update();
 }

 update = () => {
 this.setState(this.store.getState());
 }

 onChange = (e) => {
 this.store.dispatch(changeUser(e.target.value));
 }

 onClick = () => {
 this.store.dispatch(changeAge());
 }

 render(){
 return (
  <div>
  <p>user: {this.state.user}, age: {this.state.age}</p>
  user: 
  <input type="text" className="input" onChange={this.onChange}/>
   
  <button className="btn" onClick={this.onClick}>年龄增长</button>
  </div>
 );
 }
}

2.2 封装代码实现 Provider

通过 react context 我们实现了对 store 的传递,到这里 Provider 的功能以及实现原理基本上应该算是清晰了,无非就是对组件进行包裹同时通过 react context 来传递共享 store;那么接下来我们通过对代码的封装来实现 Provider 组件;

Provider 组件:实现对 store 的传递
// react-redux.js
import React from 'react';
import propTypes from 'prop-types';

export class Provider extends React.Component{
 // 设置 childContext 状态值类型
 static childContextTypes = {
 store: propTypes.object
 };

 // 设置 childContext
 getChildContext(){
 return {store: this.props.store}
 }
 
 render(){
 return this.props.children;
 }
}
重写 App.js: 对 Provider 组件的调用
// App.js
import React, { Component } from 'react';
import { createStore } from './Demo/redux';
import { Provider } from './Demo/react-redux';
import { reducer } from './Demo/reducer';
import Demo from './Demo/Demo';

// 创建 store
const store = createStore(reducer);

class App extends Component {
 render() {
 // 调用接口 Provider
 return <Provider store={store}><Demo /></Provider>;
 }
}
export default App;

三、 react-redux API connect 高阶组件的实现

上文中在后代组件如果需要获取 store 则需要手动通过获取 react context 来调用 store 并且需要显性的调用 store 内部的方法来进行一些操作;接下来我们来实现这么一个高阶组件 connect,我们只需要提供所需的 redux state 以及 action 创建函数,即可通过 props 获取到相应的 redux state , 并且允许直接通过 props 调用action 创建函数来试图修改 redux state ;

创建高阶组件 connect
// react-redux.js
export const connect = (mapStateToProps, mapDispatchToProps) => (Component) => {
 return class NewComponent extends React.Component{
 render(){
  return <Component />
 }
 }
}
获取store
// react-redux.js
export const connect = (mapStateToProps, mapDispatchToProps) => (Component) => {
 return class NewComponent extends React.Component{
 // 设置 context 状态值类型
 static contextType = {
  store: propTypes.object
 };
  // [1]获取 store [2]设置空 react state
 constructor(props, context){
  super(props, context);
  this.store = context.store;
  this.state = {};
 }
 render(){
  return <Component />
 }
 }
}
添加监听对象,并尝试通过 props 将状态传递给子组件
export const connect = (mapStateToProps, mapDispatchToProps) => (Component) => {
 return class NewComponent extends React.Component{
 static contextType = {
  store: propTypes.object
 };
 constructor(props, context){
  super(props, context);
  this.store = context.store;
  this.state = {};
 }
  // [1]添加监听对象 [2]手动执行监听对象,初始化 react state
 componentDidMount(){
  this.store.subscribe(this.update);
  this.update();
 }
 
 update = () => {
  // 获取全部redux state 并添加到 react state
  const state = this.store.getState();
  this.setState(state);
 }
 render(){
  // 通过 props 将 react state 全部传给子组件
  return <Component {...this.state} />
 }
 }
}
通过 mapStateToProps 获取指定 redux state
// react-redux.js
export const connect = (mapStateToProps, mapDispatchToProps) => (Component) => {
 return class NewComponent extends React.Component{
 static contextType = {
  store: propTypes.object
 };
 constructor(props, context){
  super(props, context);
  this.store = context.store;
  this.state = {};
 }
 componentDidMount(){
  this.store.subscribe(this.update);
  this.update();
 }
 
 update = () => {
  // 执行 mapStateToProps 只获取用户指定需求的 state
  const state = this.store.getState();
  const filterState = mapStateToProps(state);
  this.setState(filterState);
 }
 render(){
  return <Component {...this.state} />
 }
 }
}
通过 mapDispatchToProps 获取 action 创建函数: 使用 dispatch 包裹后返回
// react-redux.js
// react-redux.js
export const connect = (mapStateToProps, mapDispatchToProps) => (Component) => {
 return class NewComponent extends React.Component{
 static contextTypes = {
  store: propTypes.object
 };
 constructor(props, context){
  super(props, context);
  this.store = context.store;
  this.state = {};
 }
 componentDidMount(){
  this.store.subscribe(this.update);
  this.update();
 }
 
 update = () => {
  // 处理 state ===> 获取用户指定的 state
  const state = this.store.getState();
  const filterState = mapStateToProps(state);

  // 使用 dispatch 对 mapDispatchToProps 中的 action 创建函数进行包裹后返回
  const actionFun = {};
  for(let key in mapDispatchToProps){
  actionFun[key] = (...args) => {
   this.store.dispatch(mapDispatchToProps[key](...args));
  }
  }
 // 一种简写方式: 骚操作
 // const actionFun = Object.keys(mapDispatchToProps)
 // .reduce((total, item) => {
 // return { ...total, [item]: (...args) => {dispatch(mapDispatchToProps[item](...args));}
 // } } ,{});

  this.setState({...filterState, ...actionFun});
 }
 render(){
  return <Component {...this.state} />
 }
 }
}
调用高阶组件:修改 Demo.jsx
// Demo.jsx
import React from 'react';
import { changeAge, changeUser } from './actionCreate';
import { connect } from './react-redux';
import './style.css';

// 编写 mapStateToProps 参数 redux state 返回所需的 redux state
const mapStateToProps = (state) => {
 return {user: state.user, age: state.age};
}

// 调用高阶组件
@connect(mapStateToProps, {changeAge, changeUser})
export default class Demo extends React.Component{
 onChange = (e) => {
 this.props.changeUser(e.target.value);
 }
 onClick = () => {
 this.props.changeAge();
 }
 render(){
 return (
  <div>
  <p>user: {this.props.user}, age: {this.props.age}</p>
  user: 
  <input type="text" className="input" onChange={this.onChange}/>
   
  <button className="btn" onClick={this.onClick}>年龄增长</button>
  </div>
 );
 }
}

四、redux API bindactioncreators 的实现

在上文我们对 mapDispatchToProps 的处理过程就是 API bindactioncreators 的功能: 将给定 action 创建函数使用 dispatch 进行包裹后返回;

封装 bindactioncreators
// redux.js
export const bindactioncreators = (mapDispatchToProps, dispatch) => {
 const actionFun = {};
 // 遍历 mapDispatchToProps 中每个 action 创建函数 并使用 dispatch 包裹后返回
 for(let key in mapDispatchToProps){
 actionFun[key] = (...args) => {
  dispatch(mapDispatchToProps[key](...args));
 }
 }

 return actionFun;
 // 一种简写方式: 骚操作
 // return actionFun = Object.keys(mapDispatchToProps)
 // .reduce((total, item) => {
 // return { ...total, [item]: (...args) => {dispatch(mapDispatchToProps[item](...args));}
 // } } ,{});
}
修改 connect :
// react-redux.js
import { bindactioncreators } from './redux';
....
export const connect = (mapStateToProps, mapDispatchToProps) => (Component) => {
 return class NewComponent extends React.Component{
 static contextTypes = {
  store: propTypes.object
 };
 constructor(props, context){
  super(props, context);
  this.store = context.store;
  this.state = {};
 }
 componentDidMount(){
  this.store.subscribe(this.update);
  this.update();
 }
 
 update = () => {
  const state = this.store.getState();
  const filterState = mapStateToProps(state);
  
  // 调用 API bindactioncreators 
  // 对 mapDispatchToProps 内每个 action 创建函数使用 dispatch 进行包裹后返回
  const actionFun = bindactioncreators(mapDispatchToProps, this.store.dispatch);
  this.setState({...filterState, ...actionFun});
 }
 render(){
  return <Component {...this.state} />
 }
 }
}

五、redux API applyMiddleware 的实现

到此简化版的 react-redux 算是已经初步完成,但是假如我们想要我们的 age 值的增长是一个异步操作,比如:通过按钮点击后经过两秒再修改 age ,而不是一点击按钮就立即修改值;这样我们又该怎么实现呢?

当然我们可以通过 setTimeout 两秒后再执行 action 创建函数,比如这样:

onClick = () => {
 setTimeout(()=>{
  // 两秒后执行 action 创建函数
  this.props.changeAge();
 }, 2000);
}

但是呢事实上我们并不愿意像上面那么整,我们想要这么一种效果:我们只需要简单的调用 action 创建函数即可实现异步操作,而不是需要进行额外的操作;这时我们就需要为我们的 react-redux 编写一个中间件来实现这么一个效果;

5.1 准备工作

新增action 创建函数

  在这之前我们所有的 acton 创建函数都是直接返回一个 action 对象,下面我们写一个不一样的 action 创建函数, 它返回的不再是一个 action 对象而是一个函数,并且该函数接收两个参数 dispatch 以及 getState, 在该函数内部我们进行相应的异步操作,比如:修改 age 值;

// actionCreate.js
export const asyncChangeAge = () => {
 // 返回函数
 return (dispatch, getState) => {
 setTimeout(v=>{
  console.log('==>', getState());
  dispatch({type: 'AGE_GROW'});
 }, 1000);
 }
}
修改页面:新增按钮并绑定点击事件,并且调用 asyncChangeAge 函数;
// Demo.jsx
// Demo.jsx
import React from 'react';
import './style.css';
// 导入 asyncChangeAge
import { changeAge, changeUser, asyncChangeAge } from './actionCreate';
import { connect } from './react-redux';

const mapStateToProps = (state) => {
 return {user: state.user, age: state.age};
}

// 添加 asyncChangeAge
@connect(mapStateToProps, {changeAge, changeUser, asyncChangeAge})
export default class Demo extends React.Component{
 onChange = (e) => {
 this.props.changeUser(e.target.value);
 }
 onClick = () => {
  this.props.changeAge();
 }
 // 点击事件
 onClickAsync = () => {
 this.props.asyncChangeAge();
 }
 render(){
 return (
  <div>
  <p>user: {this.props.user}, age: {this.props.age}</p>
  user: 
  <input type="text" className="input" onChange={this.onChange}/>
   
  <button className="btn" onClick={this.onClick}>年龄增长</button>
  {/* 新增按钮 */}
  <button className="btn" onClick={this.onClickAsync}>
   异步增长
  </button>
  </div>
 );
 }
}
页面的变化其实很简单就是新增了一个按钮:

浅谈redux以及react-redux简单实现

5.2 需求实现

接下来我们先什么都不考虑先来实现我们的需求,现在 action 创建函数 asyncChangeAge 因为返回的是一个对象,其 type 值为 undefined 所以当我们点击按钮时 reducer 将会一直匹配到默认情况,返回的将是当前的状态,接下来我们先让我们的 action 创建函数 asyncChangeAge 生效,达到异步修改状态的作用;

扩展 createStore

既然 asyncChangeAge 返回的不再是一个 action 对象,而是一个函数;那么其实我们要做的事情是很简单的,我们只需要针对 createStore 中的返回值 dispatch 进行一个简单的扩展即可;通过判断 dispatch 中的 action 参数是否是函数而进行不同的操作:

// redux.js
export const createStore = (reducer) => {
 ......
 // 在createStore 我们对返回值 dispatch 进行了封装
 const dispatchExtend = (action) => {
 if(typeof action === 'function'){
  // action 为函数,执行函数
  action(dispatch, getState);
 } else {
  // action 为非函数(对象)调用dispatch
  dispatch(action);
 }
 }
 return {getState, dispatch: dispatchExtend, subscribe};
}

5.3 抽离封装

上文我们通过对 createStore 的返回值 dispatch 进行了扩展,实现了 redux-react 的异步操作,但问题是我们将代码写死在 createStore 中了,redux-react 的异步操作应该是一个可选项而不应该是必选项;

重新扩展 createStore :

新增参数 middleware (函数), 在函数 createStore 开始位置判断 middleware 是否存在,存在则执行;

// redux.js
export const createStore = (reducer, middleware) => {
 // 判断 middleware 是否存在,存在则执行
 if(middleware){
 return middleware(createStore)(reducer);
 }

 let state;
 const listeners = [];

 const getState = () => {
 return state;
 }

 const dispatch = (action) => {
 state = reducer(state, action);
 listeners.forEach(v => v());
 }

 const subscribe = (listener) => {
 listeners.push(listener);
 }

 dispatch({type: '%$&HJKAJJHDJHJ'});

 return {getState, dispatch, subscribe};
}
编写函数 applyMiddleware ,在创建 store 时 作为 createStore 第二参数
// App.js
const applyMiddleware = (createStore) => (redux)=> {
 // 在这里进行创建 store
 const store = createStore(redux);
 // 返回store
 return {...store}
}

const store = createStore(reducer, applyMiddleware);
在 applyMiddleware 函数内扩展 dispatch

上文 applyMiddleware 函数并其实没做任何事情, 只是在 createStore 函数外面套了一层函数,那么接下来我们做点正事,来扩展一下我们的 dispatch

// App.js
const applyMiddleware = (createStore) => (redux)=> {
 const store = createStore(redux);

 const midApi = {
 getState: store.getState,
 dispatch: (...args) => {dispatch(...args);}
 };

 const dispatch = (action) => {
 if( typeof action === 'function' ){
  action(midApi.dispatch, midApi.getState);
 } else {
  store.dispatch(action);
 }
 }

 return {
 ...store,
 dispatch
 };
}

5.4 扩展分离

上文已经实现了我们想要的效果了,我们在 applyMiddleware 对 dispatch 进行了扩展;然而我们是那么容易满足的嘛,当然不是的!! applyMiddleware 中对 dispatch 的扩展我们还可以将其单独提出来封装成一个函数;

重写 applyMiddleware ,再给 applyMiddleware 包裹一层函数: 将对 dispatch 的扩展抽离,封装成方法;
// App.js
const applyMiddleware = (middleware) => (createStore) => (redux)=> {
 const store = createStore(redux);

 const midApi = {
 getState: store.getState,
 dispatch: (...args) => {dispatch(...args);}
 };

 const dispatch = middleware(midApi)(store.dispatch);

 return {
 ...store,
 dispatch
 };
}
thunk 中间件: 其实 thunk 才是真正的中间件;applyMiddleware 只是用来绑定中间件的
// App.js 
const thunk = ({dispatch, getState}) => next => (action) => {
 if(typeof action === 'function'){
 action(dispatch, getState);
 } else {
 next(action);
 }
};
在调用 createStore 时绑定中间件 thunk
// App.jsx
const store = createStore(reducer, applyMiddleware(thunk));

5.5 代码整理

这一步只是将 applyMiddleware 函数移到 redux.js 文件中;同时将 thunk 函数写到文件 thunk.jsx 中,然后在 App.js 中引用 applyMiddleware 以及 thunk 而已;

看下最终效果(效果和上一个录屏是一样样的)

浅谈redux以及react-redux简单实现

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
javascript onkeydown,onkeyup,onkeypress,onclick,ondblclick
Feb 04 Javascript
silverlight线程与基于事件驱动javascript引擎(实现轨迹回放功能)
Aug 09 Javascript
JQuery插件fancybox无法在弹出层使用左右键的解决办法
Dec 25 Javascript
Node.js文件操作详解
Aug 16 Javascript
jquery实现的代替传统checkbox样式插件
Jun 19 Javascript
JS+CSS实现的蓝色table选项卡效果
Oct 08 Javascript
EasyUI在表单提交之前进行验证的实例代码
Jun 24 Javascript
jQuery插件passwordStrength密码强度指标详解
Jun 24 Javascript
jQuery实现滚动条滚动到子元素位置(方便定位)
Jan 08 Javascript
angular.js+node.js实现下载图片处理详解
Mar 31 Javascript
JS实现标签滚动切换效果
Dec 25 Javascript
vue-cli与webpack处理静态资源的方法及webpack打包的坑
May 15 Javascript
Vue封装的可编辑表格插件方法
Aug 28 #Javascript
JavaScript使用递归和循环实现阶乘的实例代码
Aug 28 #Javascript
vue-router路由懒加载的实现(解决vue项目首次加载慢)
Aug 28 #Javascript
JS实现Cookie读、写、删除操作工具类示例
Aug 28 #Javascript
vue组件开发之用户无限添加自定义填写表单的方法
Aug 28 #Javascript
vue.js添加一些触摸事件以及安装fastclick的实例
Aug 28 #Javascript
vue-image-crop基于Vue的移动端图片裁剪组件示例
Aug 28 #Javascript
You might like
一个PHP分页类的代码
2011/05/18 PHP
php投票系统之增加与删除投票(管理员篇)
2016/07/01 PHP
Yii框架中jquery表单验证插件用法示例
2016/10/18 PHP
PHP 实现人民币小写转换成大写的方法及大小写转换函数
2017/11/17 PHP
thinkPHP3.2.3实现阿里大于短信验证的方法
2018/06/06 PHP
实现PHP中session存储及删除变量
2018/10/15 PHP
window.requestAnimationFrame是什么意思,怎么用
2013/01/13 Javascript
jquery删除提示框弹出是否删除对话框
2014/01/07 Javascript
jQuery中innerHeight()方法用法实例
2015/01/19 Javascript
javascript实现博客园页面右下角返回顶部按钮
2015/02/22 Javascript
javascript删除元素节点removeChild()用法实例
2015/05/26 Javascript
用JavaScript显示浏览器客户端信息的超相近教程
2015/06/18 Javascript
AngularJS服务service用法总结
2016/12/13 Javascript
实例解析js中try、catch、finally的执行规则
2017/02/24 Javascript
js实现华丽的九九乘法表效果
2017/03/29 Javascript
为Jquery EasyUI 组件加上清除功能的方法(详解)
2017/04/13 jQuery
利用SpringMVC过滤器解决vue跨域请求的问题
2018/02/10 Javascript
动态加载、移除js/css文件的示例代码
2018/03/20 Javascript
H5+C3+JS实现五子棋游戏(AI篇)
2020/05/28 Javascript
使用Vue实现调用接口加载页面初始数据
2019/10/28 Javascript
详解如何在vue+element-ui的项目中封装dialog组件
2020/12/11 Vue.js
[41:11]完美世界DOTA2联赛PWL S2 Inki vs Magma 第一场 11.22
2020/11/24 DOTA
在Django的模板中使用认证数据的方法
2015/07/23 Python
Python3操作SQL Server数据库(实例讲解)
2017/10/21 Python
如何基于Python + requests实现发送HTTP请求
2020/01/13 Python
python实现最速下降法
2020/03/24 Python
树莓派4B安装Tensorflow的方法步骤
2020/07/16 Python
俄罗斯运动、健康和美容产品在线商店:Lactomin.ru
2020/07/23 全球购物
硕士研究生自我鉴定
2013/11/08 职场文书
初三学习决心书
2014/03/11 职场文书
留学推荐信范文
2014/05/10 职场文书
三好学生个人先进事迹材料
2014/05/17 职场文书
战略合作意向书
2014/07/29 职场文书
庆国庆国旗下讲话稿2014
2014/09/21 职场文书
加强作风建设工作总结
2014/10/23 职场文书
妇产科护理心得体会
2016/01/22 职场文书