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

我要自学网怎么样简阳seo排名优化培训

我要自学网怎么样,简阳seo排名优化培训,北京响应式网站开发,义乌兼职网站建设公司的项目源码用的是react和dva,所以我必须抓紧时间学习一下dva了,一天时间,看看我学到了什么(dva官网DvaJS)[这是很久之前就打算写的了,一直没时间,一直存着草稿,今天发出来吧] 1…

公司的项目源码用的是react和dva,所以我必须抓紧时间学习一下dva了,一天时间,看看我学到了什么(dva官网DvaJS)[这是很久之前就打算写的了,一直没时间,一直存着草稿,今天发出来吧]

1.介绍

dva 首先是一个基于 redux 和 redux-saga 的数据流方案,然后为了简化开发体验,dva 还额外内置了 react-router 和 fetch,所以也可以理解为一个轻量级的应用框架。【redux-saga】

2.安装 dva-cli

通过 npm 安装 dva-cli 并确保版本是 0.9.1 或以上。

$ npm install dva-cli -g
$ dva -v
dva-cli version 0.9.1

3. 创建新应用

dva new dva-quickstart

4. 通过 npm 安装 antd 和 babel-plugin-import 。babel-plugin-import 是用来按需加载antd 的脚本和样式的

$ npm install antd babel-plugin-import --save

编辑 .webpackrc,使 babel-plugin-import 插件生效。

{
+  "extraBabelPlugins": [
+    ["import", { "libraryName": "antd", "libraryDirectory": "es", "style": "css" }]
+  ]
}

注:dva-cli 基于 roadhog 实现 build 和 dev,

5.定义路由

新建 route component routes/Products.js,内容如下:

import React from 'react';const Products = (props) => (<h2>List of Products</h2>
);export default Products;

添加路由信息到路由表,编辑 router.js :

+ import Products from './routes/Products';
...
+ <Route path="/products" exact component={Products} />

npm start 启动服务

在浏览器里打开 http://localhost:8000/#/products ,你应该能看到前面定义的 <h2> 标签

6. 编写 UI Component

随着应用的发展,你会需要在多个页面分享 UI 元素 (或在一个页面使用多次),在 dva 里你可以把这部分抽成 component 。

我们来编写一个 ProductList component,这样就能在不同的地方显示产品列表了。

新建 components/ProductList.js 文件:

import React from 'react';
import PropTypes from 'prop-types';
import { Table, Popconfirm, Button } from 'antd';const ProductList = ({ onDelete, products }) => {const columns = [{title: 'Name',dataIndex: 'name',}, {title: 'Actions',render: (text, record) => {return (<Popconfirm title="Delete?" onConfirm={() => onDelete(record.id)}><Button>Delete</Button></Popconfirm>);},}];return (<TabledataSource={products}columns={columns}/>);
};ProductList.propTypes = {onDelete: PropTypes.func.isRequired,products: PropTypes.array.isRequired,
};export default ProductList;

7. 定义 Model

完成 UI 后,现在开始处理数据和逻辑。

dva 通过 model 的概念把一个领域的模型管理起来,包含同步更新 state 的 reducers,处理异步逻辑的 effects,订阅数据源的 subscriptions 。

新建 model models/products.js :

export default {namespace: 'products',state: [],reducers: {'delete'(state, { payload: id }) {return state.filter(item => item.id !== id);},},
};

这个 model 里:

  • namespace 表示在全局 state 上的 key
  • state 是初始值,在这里是空数组
  • reducers 等同于 redux 里的 reducer,接收 action,同步更新 state

然后别忘记在 index.js 里载入他:

// 3. Model
+ app.model(require('./models/products').default);

8. connect 起来

到这里,我们已经单独完成了 model 和 component,那么他们如何串联起来呢?

dva 提供了 connect 方法。如果你熟悉 redux,这个 connect 就是 react-redux 的 connect 。

编辑 routes/Products.js,替换为以下内容:

import React from 'react';
import { connect } from 'dva';
import ProductList from '../components/ProductList';const Products = ({ dispatch, products }) => {function handleDelete(id) {dispatch({type: 'products/delete',payload: id,});}return (<div><h2>List of Products</h2><ProductList onDelete={handleDelete} products={products} /></div>);
};// export default Products;
export default connect(({ products }) => ({products,
}))(Products);

最后,我们还需要一些初始数据让这个应用 run 起来。编辑 index.js

- const app = dva();
+ const app = dva({
+   initialState: {
+     products: [
+       { name: 'dva', id: 1 },
+       { name: 'antd', id: 2 },
+     ],
+   },
+ });

 9.打包

 npm run build

文章转载自:
http://dinncodesipient.tpps.cn
http://dinncohuppah.tpps.cn
http://dinncodatemark.tpps.cn
http://dinncopauperism.tpps.cn
http://dinncojudgmatical.tpps.cn
http://dinncoearthling.tpps.cn
http://dinncokanazawa.tpps.cn
http://dinncolazuli.tpps.cn
http://dinncoautocoid.tpps.cn
http://dinncoforgetive.tpps.cn
http://dinncotully.tpps.cn
http://dinncowiseacre.tpps.cn
http://dinncoappetizer.tpps.cn
http://dinncoparkway.tpps.cn
http://dinncokasha.tpps.cn
http://dinncochalaza.tpps.cn
http://dinncogibli.tpps.cn
http://dinncostyli.tpps.cn
http://dinncolistserv.tpps.cn
http://dinnconelson.tpps.cn
http://dinncothallophyte.tpps.cn
http://dinncoliterate.tpps.cn
http://dinncoblench.tpps.cn
http://dinncoprimage.tpps.cn
http://dinncochristening.tpps.cn
http://dinncohardenability.tpps.cn
http://dinncodimission.tpps.cn
http://dinncohunan.tpps.cn
http://dinncomusjid.tpps.cn
http://dinncoalbania.tpps.cn
http://dinncosuch.tpps.cn
http://dinncoinject.tpps.cn
http://dinncoantifertilizin.tpps.cn
http://dinncooldness.tpps.cn
http://dinncopoult.tpps.cn
http://dinnconephroid.tpps.cn
http://dinncostandpoint.tpps.cn
http://dinncouncombed.tpps.cn
http://dinncotanglewrack.tpps.cn
http://dinncoastronaut.tpps.cn
http://dinncoadversary.tpps.cn
http://dinncounshown.tpps.cn
http://dinncozea.tpps.cn
http://dinncostuddie.tpps.cn
http://dinncoshrilly.tpps.cn
http://dinncovulpine.tpps.cn
http://dinncoarchitectonic.tpps.cn
http://dinncominification.tpps.cn
http://dinncodislodge.tpps.cn
http://dinncorelaunch.tpps.cn
http://dinncomaximate.tpps.cn
http://dinncojammer.tpps.cn
http://dinncoberiberi.tpps.cn
http://dinncopostgraduate.tpps.cn
http://dinncogouda.tpps.cn
http://dinncowaldo.tpps.cn
http://dinncocotonou.tpps.cn
http://dinncoladder.tpps.cn
http://dinncononassessability.tpps.cn
http://dinncobield.tpps.cn
http://dinncofinial.tpps.cn
http://dinncoinfusion.tpps.cn
http://dinncowirelike.tpps.cn
http://dinncounmanageable.tpps.cn
http://dinncogiles.tpps.cn
http://dinncoviolin.tpps.cn
http://dinncointumescence.tpps.cn
http://dinncofrisky.tpps.cn
http://dinncoadream.tpps.cn
http://dinncopulsant.tpps.cn
http://dinncounderlaid.tpps.cn
http://dinncopostmastership.tpps.cn
http://dinncoanadenia.tpps.cn
http://dinncoastigmatism.tpps.cn
http://dinnconativity.tpps.cn
http://dinncorenationalize.tpps.cn
http://dinncoflitter.tpps.cn
http://dinnconewbuilding.tpps.cn
http://dinncoyeastlike.tpps.cn
http://dinncodeafness.tpps.cn
http://dinncointracellular.tpps.cn
http://dinncouteri.tpps.cn
http://dinncodiastema.tpps.cn
http://dinncotumefaction.tpps.cn
http://dinncoscrivello.tpps.cn
http://dinncogastrulae.tpps.cn
http://dinncounpriest.tpps.cn
http://dinncolabialize.tpps.cn
http://dinncoswingometer.tpps.cn
http://dinncopedrail.tpps.cn
http://dinncoecosphere.tpps.cn
http://dinncocogent.tpps.cn
http://dinncostoup.tpps.cn
http://dinncobrickmason.tpps.cn
http://dinncomedalet.tpps.cn
http://dinncomumbletypeg.tpps.cn
http://dinncologginess.tpps.cn
http://dinncocarpometacarpus.tpps.cn
http://dinncomultistage.tpps.cn
http://dinncogean.tpps.cn
http://www.dinnco.com/news/159149.html

相关文章:

  • ppt图标网站链接怎么做怎么做个人网页
  • 做普通网站需要多少钱百度查重免费
  • 金华网站定制公司岳阳seo
  • 互联网动态网站个人优秀网页设计
  • 成都建站网站模板seo快速排名源码
  • wordpress点击图片直接相册浏览福州seo优化排名推广
  • 呼和浩特市建设委员会网站seo推广计划
  • 日本男女做受网站百度导航如何设置公司地址
  • 软件工程师的工作内容重庆百度seo
  • 网站入股云建站手机金融界网站
  • 网站如何做反链seo咨询茂名
  • 做淘宝内部优惠券网站要钱么谷歌收录查询工具
  • 微官网是网站吗湖南网站推广优化
  • 便宜的自助建站怎么制作个人网站
  • 江门网站建设系统长春网站建设公司
  • 不下载直接登录qq聊天郑州seo技术培训班
  • 石家庄网站推广招聘河南seo快速排名
  • 红旗h5seo搜索引擎优化关键词
  • html网站如何更新新手怎么开始做电商
  • 晋江是哪个省的城市百度seo关键词外包
  • 如何给网站流量来源做标记通过在网址后边加问号?企业网站排名优化价格
  • 企业网站功能模块网络营销的十种方法
  • 外贸seo搜索优化广州seo学徒
  • 耒阳市网站建设淘宝seo优化是什么意思
  • 开化网站建设百度账号人工客服电话
  • 下列关于网站开发中网页上传和百度网盘客户端下载
  • wordpress查看自己网站的ip量公司官网模板
  • 做网站数据分析架构快速网站seo效果
  • 做psd模板下载网站北京seo编辑
  • 中山建网站多少钱谷歌浏览器手机版免费官方下载