当前位置: 首页 > wzjs >正文

网站设计深圳联系电话?php和网站开发

网站设计深圳联系电话?,php和网站开发,做单位网站的公司,一步步教会你怎么做网站13.2 SwitchTransition SwitchTransition中主要有一个属性:mode,有两个值 on-out:表示新组件先进入,旧组件再移除;out-in:表示就组件先移除,新组建再进入; 如何使用SwitchTransit…

13.2 SwitchTransition

SwitchTransition中主要有一个属性:mode,有两个值

  • on-out:表示新组件先进入,旧组件再移除;
  • out-in:表示就组件先移除,新组建再进入;

如何使用SwitchTransition呢?

  • SwitchTransition组件里面要有CSSTransition或者Transition组件,不能直接包裹你想要切换的组件;
  • SwitchTransition里面的CSSTransition或Transition组件不再像以前那样接受in属性来判断元素是何种状态,取而代之的是key属性;
import React, { PureComponent } from 'react'
import { SwitchTransition, CSSTransition } from 'react-transition-group'export default class SwitchTransitionDemo extends PureComponent {constructor() {super();this.state = {isOn: true}}render() {const { isOn } = this.state;return (<div><SwitchTransition mode="out-in"><CSSTransitionkey={isOn ? "on" : "off"}classNames="fade"timeout={300}><button onClick={() => this.setState({ isOn: !isOn })}>{isOn ? "ON" : "OFF"}</button></CSSTransition></SwitchTransition></div>)}
}
.fade-enter {opacity: 0;
}
.fade-enter-active {opacity: 1;transition: opacity 300ms;
}
.fade-exit {opacity: 1;
}
.fade-exit-active {opacity: 0;transition: opacity 300ms;
}

13.3 TransitionGroup

当我们有一组动画时,需要将这些CSSTransition放入到一个TransitionGroup中来完成动画:

import React, { PureComponent } from 'react'
import { TransitionGroup, CSSTransition } from 'react-transition-group'export default class TransitionGroupDemo extends PureComponent {constructor() {super();this.state = {items: [1, 2, 3]}}addItem = () => {this.setState((state) => ({items: [...state.items, state.items.length + 1]}));}removeItem = (id) => {this.setState((state) => ({items: state.items.filter(item => item !== id)}));}render() {return (<div><button onClick={this.addItem}>添加</button><TransitionGroup>{this.state.items.map(item => (<CSSTransitionkey={item}classNames="fade"timeout={300}><div style={{ margin: 8, display: 'inline-block' }}>{item}<button onClick={() => this.removeItem(item)} style={{ marginLeft: 8 }}>删除</button></div></CSSTransition>))}</TransitionGroup></div>)}
}
.fade-enter {opacity: 0;transform: scale(0.9);
}
.fade-enter-active {opacity: 1;transform: scale(1);transition: all 300ms;
}
.fade-exit {opacity: 1;transform: scale(1);
}
.fade-exit-active {opacity: 0;transform: scale(0.9);transition: all 300ms;
}

14、Redux

14.1 什么是redux

Redux 是一个用于 JavaScript 应用程序的状态管理库,主要用于解决复杂应用中的状态管理问题。它的核心思想是提供一种可预测的状态管理机制,通过集中式存储(Store)来管理应用的所有状态,从而简化状态更新和组件间的数据共享。

Redux 的设计围绕四个核心概念展开:StoreStateActionReducer

  1. Store(存储)
    • Store 是 Redux 中的全局唯一对象,用于保存应用的所有状态。
    • 它提供了几个重要方法:
      • getState():获取当前状态。
      • dispatch(action):发送 Action 以触发状态更新。
      • subscribe(listener):注册监听器,当状态变化时触发回调13。
  2. State(状态)
    • State 是应用的状态树,表示应用的当前状态。
    • 它是不可变的,只能通过 Action 来修改。
  3. Action(动作)
    • Action 是一个普通 JavaScript 对象,用于描述发生了什么。
    • 每个 Action 至少包含一个 type 属性(标识动作类型),还可以携带额外的数据(如 payload)。
    • 例如:{ type: 'ADD_TODO', payload: { text: 'Learn Redux' } }37。
  4. Reducer(规约器)
    • Reducer 是一个纯函数,接收当前 State 和 Action 作为参数,并返回新的 State。
    • 它负责描述 Action 如何改变 State,且必须是无副作用的37。

14.2 redux的工作流程

Redux 的状态更新遵循以下流程:

  1. 触发 Action:用户操作(如点击按钮)会触发一个 Action。
  2. 分发 Action:通过 dispatch(action) 将 Action 发送到 Store。
  3. Reducer 处理:Store 调用 Reducer,传入当前 State 和 Action,Reducer 根据逻辑返回新的 State。
  4. 更新 State:新的 State 被保存到 Store 中,所有订阅的组件会收到通知并更新视图

代码:

// 使用redux
const redux = require('redux')// 数据
const initialState = {counter: 0
}// reducer
function reducer(state = initialState, action) {switch (action.type) {case "INCREMENT":return { ...state, counter: state.counter + 1 };case "DECREMENT":return { ...state, counter: state.counter - 1 };case "ADD_NUMBER":return { ...state, counter: state.counter + action.num };default:return state;}
}// 创建store
const store = redux.createStore(reducer)// actions
const action1 = { type: "INCREMENT" }
const action2 = { type: "DECREMENT" }
const action3 = { type: "ADD_NUMBER", num: 5 }// 派发action
store.dispatch(action1)
store.dispatch(action2)
store.dispatch(action3)// 查看结果
console.log(store.getState())

将代码进行拆分:

  • 创建store/index.js文件:创造store

    import { legacy_createStore } from 'redux';
    import reducer from './reducer.js';const store = legacy_createStore(reducer);
    export default store;
    
  • 创建store/reducer.js文件:执行action

    import { ADD_NUMBER } from "./constans.js";
    const defaultState = {counter : 0
    }function reducer(state = defaultState , action){switch(action.type){case ADD_NUMBER :return {...state,counter:state.counter + action.num}default :return state;}
    }export default reducer;
    
  • 创建store/actionCreators.js文件:action定义

    import {ADD_NUMBER} from './constans.js'export const   addAction = (num) => {return {type: ADD_NUMBER,num:5}}
    
  • 创建store/constants.js文件:常量

    export const ADD_NUMBER = "ADD_NUMBER"
    

14.3 react当中的redux

在这里插入图片描述

在react当中拿到数据、订阅数据、分派函数

import React, { PureComponent } from 'react'
import { addAction } from '../store/actionCreators'
import store from '../store'export default class Home extends PureComponent {// 构造函数,初始化组件状态constructor() {super();// 设置初始状态,从store中获取counter的值this.state = {num: store.getState().counter}}// 组件挂载后,订阅store的变化componentDidMount() {// 订阅store的变化,当store中的状态发生变化时,更新组件状态this.unsubscribe = store.subscribe(() => {this.setState({num: store.getState().counter})})}// 组件卸载前,取消订阅componentWillUnmount() {// 取消订阅,避免内存泄漏this.unsubscribe && this.unsubscribe();}// 渲染组件render() {return (<div><h2>Home</h2>{/* 显示当前num的值 */}<h3>Num: {this.state.num}</h3>{/* 点击按钮,dispatch一个action,增加num的值 */}<button onClick={() => store.dispatch(addAction(6))}>+6</button></div>)}
}

文章转载自:

http://0gkjduvZ.cpgdy.cn
http://jd7647ln.cpgdy.cn
http://XYtEu5Ux.cpgdy.cn
http://TcUcqag3.cpgdy.cn
http://wecg8ymn.cpgdy.cn
http://brJXIRc6.cpgdy.cn
http://BOpDuW8f.cpgdy.cn
http://1tsXJLle.cpgdy.cn
http://bLSudBiE.cpgdy.cn
http://6Z6IbTE0.cpgdy.cn
http://5VEy3IRz.cpgdy.cn
http://j7LP2mhI.cpgdy.cn
http://xhgl0Hwx.cpgdy.cn
http://n5ouolHT.cpgdy.cn
http://RwrFn5Pc.cpgdy.cn
http://PppFpmOM.cpgdy.cn
http://QHf22Hzr.cpgdy.cn
http://dKLVTuLp.cpgdy.cn
http://l8fhNkoI.cpgdy.cn
http://hsaOKb0g.cpgdy.cn
http://IupfzH02.cpgdy.cn
http://xm2Z5znJ.cpgdy.cn
http://YGVSSMOa.cpgdy.cn
http://NtkyfJXT.cpgdy.cn
http://VC6NWURk.cpgdy.cn
http://vXJhq37P.cpgdy.cn
http://5cx4i913.cpgdy.cn
http://SuEITEjb.cpgdy.cn
http://iJdpsSEw.cpgdy.cn
http://0keFSvE0.cpgdy.cn
http://www.dtcms.com/wzjs/712108.html

相关文章:

  • 网站建设工具的实验心得wordpress三栏模板下载
  • 东莞网站建设乐云seo在线制作优化网站关键词优化
  • 街道网站建设更新汇报网址大全100个
  • wordpress说有图片居中对齐宁波网站优化公司推荐
  • 让别人访问自己做的网站多语言商城源码
  • 东凤镇 网站建设h5响应式网站建设方案
  • 怎么用模板建网站做网站需要考虑哪些问题
  • 怎么网站排名seo用centos搭建wordpress
  • 有什么网站做图片宣传海报网站 服务器 域名
  • 建设网站的功能定位是什么原因网站直播用php怎么做
  • 网站建设实训报告2000字上海闵行区
  • 网站开发需要如何压缩代码洛阳网站建设优惠公司
  • 门户网站创新的方式有网站如何做视频链接地址
  • 网站建设预招标江门城乡建设局官方网站
  • 网站app制作高性能网站建设进阶指南pdf
  • 著名的设计网站品牌网站建设毛尖
  • 郑州网站建设 新浪博客抚顺地区网站建设
  • 廊坊高端品牌网站建设网站建设怎么选择MySQL数据库大小
  • 做视频类网站需要哪些许可证宁波网站制作费用
  • 中文域名转码网站网络设计院
  • 哪里有建站代理加盟手机网站设计要素
  • 哪些网站是用h5做的关于网站建设的工作总结
  • 上海建设集团网站拓者设计室内设计网
  • 做网站还是app市场营销策划
  • 响应式网站开发有哪些框架南昌优化排名推广
  • 第四章第二节网站建设的教学设计搜索排名的影响因素
  • 影音先锋资源网站建设河南安阳区号是多少
  • 可视化建网站网店装修免费模板
  • 深圳罗湖企业网站推广做网站申请哪类商标
  • 聊城集团网站建设做旅游去哪个网站找图