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

做网站什么系统简单/短期的技能培训有哪些

做网站什么系统简单,短期的技能培训有哪些,app制作网站,哪个网站做投票链接模板好看文章目录文章参考案例描述定义modeleffects 参数介绍connect关联model和UI组件启动文件引入 model配置文章参考 https://dvajs.com/guide/introduce-class.html#reducerJavaScript异步编程:Generator与Async 案例描述 定义model 前面写过redux相关的笔记&#xf…

文章目录

    • 文章参考
    • 案例描述
      • 定义model
        • effects 参数介绍
      • connect关联model和UI组件
      • 启动文件引入 model配置

文章参考

  1. https://dvajs.com/guide/introduce-class.html#reducer
  2. JavaScript异步编程:Generator与Async

案例描述

定义model

前面写过redux相关的笔记,与redux做比较来理解model

  1. namespace:model的命名空间,namespace也是全局state的属性,只支持字符串格式。
  2. state:初始值。
  3. reducers:以key/value的格式来定义reducer。用于处理同步操作,唯一可以修改state的地方,由action触发。格式为:(state, action) => newState 或者 [(state, action) => newState, enhancer]。
  4. effects:以key/value格式定义effect。用于处理异步操作和业务逻辑,不直接修改state。由action触发,可以触发 action,可以和服务器交互,可以获取全局 state 的数据等等。
function getServerData (step) {console.dir(arguments);return new Promise(function(resolve, reject){setTimeout(function () {resolve({step: step + 1})}, 3000)});
}export default {namespace : 'huangbiao',// State 表示 Model 的状态数据,通常表现为一个 javascript 对象(当然它可以是任何值)state : {count : 10},// Reducer 是 Action 处理器,用来处理同步操作,可以看做是 state 的计算器。它的作用是根据 Action,从上一个 State 算出当前 State。reducers : {//Reducer(也称为 reducing function)函数接受两个参数:// 之前已经累积运算的state结果 和 当前要被累积的值,返回的是一个新的累积结果add (state, userParams) {var {count} = state;var step = userParams.step;return {...state,count: count + step}},minus (state, userParams) {var {count} = state;var step = userParams.step;return {...state,count: count - step};}},// Action 处理器,处理异步动作,基于 Redux-saga 实现。// 根据函数式编程,计算以外的操作都属于 Effect,典型的就是 I/O 操作、数据库读写。effects : {// 只能定义 generater 函数,不能用async 函数// call:执行异步函数// put:发出一个 Action,类似于 dispatchsetIncrease: function* (action, { put, call }) {console.dir(arguments);// 使用 call 去调用 getServerData 方法,后面全部是 getServerData 的参数// serverData 是getServerData返回的结果var serverData = yield call(getServerData , action.step, "param_1", "6000");console.dir(serverData);// 使用 put 调用reduceryield put({type:'add',...serverData});},*setDecrease (action, { put, call }) {var serverData = yield call(getServerData , action.step, "param_1", "6000");console.dir(serverData);// 使用 put 调用reduceryield put({type:'minus',step: serverData.step});}}}

effects 参数介绍

  1. 第一个参数:是action对象(本质是一个包含type的JSON对象)
  2. 第二个参数:包含{put, call}方法的对象,其中call 是用来调用异步方法,put可以理解为与redux的dispatch方法一样,触发reducer方法
  3. call 调用的函数,第一个是Generator函数,后面的参数全部是Generator的参数

connect关联model和UI组件

import React from 'react';
import { connect } from 'dva';class reduxDemo extends React.Component {constructor (props) {super(props);}increace = () => {const {dispatch} = this.props;dispatch({// 这里要指明命名空间type: 'huangbiao/add',step: 1});}decrease = () => {const {dispatch} = this.props;dispatch({// 这里要指明命名空间type: 'huangbiao/minus',step: 3});}render () {const {count, increaceEffect, decreaseEffect} = this.propsreturn (<div><div>huangbiao.count ---- {count}</div><div><button onClick={this.increace}>添加</button></div><div><button onClick={increaceEffect}>异步添加</button></div><div><button onClick={this.decrease}>减少</button></div><div><button onClick={decreaseEffect}>异步减少</button></div></div>);}
}function mapStateToProps (state) {console.dir(state);return {count : state.huangbiao.count}
}function mapDispatchToProps (dispatch) {return {dispatch: dispatch,// 异步添加数据increaceEffect: function () {dispatch({// 这里要指明命名空间type: 'huangbiao/setIncrease',step: 2})},// 异步减少数据decreaseEffect: function () {dispatch({// 这里要指明命名空间type: 'huangbiao/setDecrease',step: 2})}}
}export default connect(mapStateToProps, mapDispatchToProps)(reduxDemo);
  1. import { connect } from 'dva'; connect 将UI组件和model关联起来
  2. connect有两个参数
    • 第一个参数:将Model中的state映射为UI组件的props属性
    • 第二个参数: 将dispatch映射为UI组件的方法

启动文件引入 model配置

import dva from 'dva';
import './index.css';// 1. Initialize
// // 创建应用
const app = dva();// 2. Plugins
// app.use({});// 3. Model
// app.model(require('./models/example').default);
app.model(require('./models/hbmodles').default);// 4. Router
// // 注册视图
app.router(require('./router').default);// 5. Start
// // 启动应用
app.start('#root');
http://www.lbrq.cn/news/1310005.html

相关文章:

  • 松桃和兴建设公司网站/360排名检测
  • 做网站的需求调研/怎样建立一个网站
  • 做金馆长网站网站/seo刷排名工具
  • python 如何做网站/百度搜图入口
  • 乌托邦网站建设/济南网站优化排名
  • 世界网站流量排名/最近五天的新闻大事
  • 自己做网站到哪里去接广告/电子商务网站设计方案
  • 辽宁省企业信息系统/seo关键词排名优化联系方式
  • 淮安市政府门户网站建设的调查报告/小红书推广方式
  • 做网站ps能用美图秀秀么/双11销量数据
  • 宁波网站建设制作价格/知名网络推广
  • 做企业网站需要买什么资料/发布会直播平台
  • 南京快速建站公司/semir是什么品牌
  • 每天做任务得钱的网站/东莞百度搜索优化
  • 哪些网站可以兼职做设计/跟我学seo
  • 怎么做跟P站一样的网站/uc浏览网页版进入
  • 卖护肤在哪个网站做宣传好/网站收录查询方法
  • 网站域名注册的相关证书证明文件/seo网站介绍
  • 网络营销公司都做什么的/长沙网站seo优化排名
  • 重庆小程序开发/360优化大师官方下载
  • win10做的网站其他电脑访问不了/知乎营销平台
  • 做网站淄博/35个成功的市场营销策划案例
  • 深圳规模较大的网站建设公司/百度网站关键词排名查询
  • 个性化定制服务的网站有哪些/百度官网平台
  • 手机网站开发看什么书/网络推广怎么做
  • 网站现状如何分析/晚上必备免费软件大全苹果
  • 一个论坛网站应该怎么做/中小企业管理培训课程
  • 云南省建设厅网站查询/优化关键词排名公司
  • 梅州市网站制作/培训学校怎么招生
  • 做博客网站怎么赚钱吗/百度快速收录教程
  • JavaScript进阶篇——第八章 原型链、深浅拷贝与原型继承全解析
  • 技术分享:如何用规则定义生成自定义文件时间戳
  • 事务~~~
  • 壹脉销客AI电子名片源码核心架构
  • Ray集群部署与维护
  • GitHub Pages+Jekyll 静态网站搭建(二)