国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

React框架Umi實戰(2)整合dva開發后臺管理系統

beita / 1644人閱讀

摘要:官方推薦結合使用更配哦,其實他們都是同一位開發者開發的,屬于阿里內部開源框架。但是名字必須為,不然不能自動注冊。只有一個的話,可以不用建目錄??赡苁俏依斫庥姓`。

umi官方推薦結合dva使用更配哦,其實他們都是同一位開發者開發的,屬于阿里內部開源框架。
1 修改.umirc.js,開啟dva支持
// ref: https://umijs.org/config/
export default {
  plugins: [
    // ref: https://umijs.org/plugin/umi-plugin-react.html
    ["umi-plugin-react", {
      antd: true,
      dva: true,
      dva: {
          immer: true
        },
      dynamicImport: false,
      title: "umis",
      dll: false,
      hardSource: false,
      routes: {
        exclude: [
          /components//,
        ],
      },
    }],
  ],
}
2 修改layouts

先搞一個后臺的布局,可以參考ANT DESIGN PRO https://pro.ant.design/
layoutsindex.js

import styles from "./index.less";
import { Layout, Menu, Breadcrumb, Icon } from "antd";
import { Component } from "react";
import Link from "umi/link";
import logo from "../assets/logo.svg";
const {Header, Content, Footer, Sider} = Layout;
const SubMenu = Menu.SubMenu;
class BasicLayout extends Component {

  constructor(props) {
    super(props);
    this.state = {
      collapsed: false,
    };
  }

  toggle = () => {
  this.setState({
    collapsed: !this.state.collapsed,
  });
}

render(){
return (
    
        
        

Ant Design Pro

Users Team} > Team 1 Team 2
{/*此處可加面包屑*/} { this.props.children }
Ant Design ?2018 Created by Ant UED
); } } export default BasicLayout;

layoutsindex.less

.logo {
  height: 64px;
  position: relative;
  line-height: 64px;
  transition: all 0.3s;
  background: #002140;
  overflow: hidden;
  img {
    display: inline-block;
    vertical-align: middle;
    height: 32px;
  }
  h1 {
    color: white;
    display: inline-block;
    vertical-align: middle;
    font-size: 20px;
    margin: 0 0 0 12px;
    font-family: "Myriad Pro", "Helvetica Neue", Arial, Helvetica, sans-serif;
    font-weight: 600;
  }
}

.trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
  transition: color .3s;
  .logo {
  height: 32px;
  background: rgba(255,255,255,.2);
  margin: 16px;
}
}

.sider {
  min-height: 100vh;
  box-shadow: 2px 0 6px rgba(0, 21, 41, 0.35);
  position: relative;
  z-index: 10;
  &.ligth {
    background-color: white;
    .logo {
      background: white;
      h1 {
        color: #002140;
      }
    }
  }
}

瀏覽器訪問你會看到如下效果:

3 改造users頁面,完成dva整個流程。

在pages下創建users目錄

創建index.js 會生成默認路由http://localhost:8000/users

import { connect } from "dva";
import { Table, Pagination, Popconfirm } from "antd";
import styles from "./users.css";
const PAGE_SIZE = 5;

function Users({ list: dataSource, total, page: current }) {
  function deleteHandler(id) {
    console.warn(`TODO: ${id}`);
  }

  const columns = [
    {
      title: "Name",
      dataIndex: "name",
      key: "name",
      render: text => {text},
    },
    {
      title: "Email",
      dataIndex: "email",
      key: "email",
    },
    {
      title: "Website",
      dataIndex: "website",
      key: "website",
    },
    {
      title: "Operation",
      key: "operation",
      render: (text, { id }) => (
        
          Edit
          
            Delete
          
        
      ),
    },
  ];

  return (
    
record.id} pagination={false} /> ); } function mapStateToProps(state) { const { list, total, page } = state.users; console.log(state.test); return { list, total, page, }; } export default connect(mapStateToProps)(Users);

創建對應的model.js,因為只有一個model所以不需要創建models目錄。但是名字必須為model.js,不然不能自動注冊。

//只有一個model的話,可以不用建models目錄。但名字必須為model。js
import * as usersService from "./service";
export default {
  namespace: "users",
  state: {
    list: [],
    total: null,
  },
  reducers: {
    save(state, { payload: { data: list, total } }) {
      return { ...state, list, total };
    },
  },
  effects: {
    *fetch({ payload: { page } }, { call, put }) {
      const { data} = yield call(usersService.fetch, { page });
      yield put({ type: "save", payload: { data, total: data.length } });
    },
  },
  subscriptions: {
    setup({ dispatch, history }) {
      return history.listen(({ pathname, query }) => {
        if (pathname === "/users") {
          dispatch({ type: "fetch", payload: query });
        }
      });
    },
  },
};

創建service.js 這個不需要約定名稱,你隨便起名字

import request from "../../utils/request";

export function fetch({ page = 1 }) {
  return request(`/api/users?_page=${page}&_limit=5`);
}

創建utils目錄,封裝統一請求api utils equest.js

import fetch from "dva/fetch";

function checkStatus(response) {
  if (response.status >= 200 && response.status < 300) {
    return response;
  }

  const error = new Error(response.statusText);
  error.response = response;
  throw error;
}

/**
 * Requests a URL, returning a promise.
 *
 * @param  {string} url       The URL we want to request
 * @param  {object} [options] The options we want to pass to "fetch"
 * @return {object}           An object containing either "data" or "err"
 */
export default async function request(url, options) {
  const response = await fetch(url, options);

  checkStatus(response);

  const data = await response.json();

  const ret = {
    data
  };
  return ret;
}

創建mock假數據 mockuser.js

export default {
  "/api/users": [
  {
    "id": 1,
    "name": "Leanne Graham",
    "username": "Bret",
    "email": "Sincere@april.biz",
    "address": {
      "street": "Kulas Light",
      "suite": "Apt. 556",
      "city": "Gwenborough",
      "zipcode": "92998-3874",
      "geo": {
        "lat": "-37.3159",
        "lng": "81.1496"
      }
    },
    "phone": "1-770-736-8031 x56442",
    "website": "hildegard.org",
    "company": {
      "name": "Romaguera-Crona",
      "catchPhrase": "Multi-layered client-server neural-net",
      "bs": "harness real-time e-markets"
    }
  },
  {
    "id": 2,
    "name": "Ervin Howell",
    "username": "Antonette",
    "email": "Shanna@melissa.tv",
    "address": {
      "street": "Victor Plains",
      "suite": "Suite 879",
      "city": "Wisokyburgh",
      "zipcode": "90566-7771",
      "geo": {
        "lat": "-43.9509",
        "lng": "-34.4618"
      }
    },
    "phone": "010-692-6593 x09125",
    "website": "anastasia.net",
    "company": {
      "name": "Deckow-Crist",
      "catchPhrase": "Proactive didactic contingency",
      "bs": "synergize scalable supply-chains"
    }
  },
  {
    "id": 3,
    "name": "Clementine Bauch",
    "username": "Samantha",
    "email": "Nathan@yesenia.net",
    "address": {
      "street": "Douglas Extension",
      "suite": "Suite 847",
      "city": "McKenziehaven",
      "zipcode": "59590-4157",
      "geo": {
        "lat": "-68.6102",
        "lng": "-47.0653"
      }
    },
    "phone": "1-463-123-4447",
    "website": "ramiro.info",
    "company": {
      "name": "Romaguera-Jacobson",
      "catchPhrase": "Face to face bifurcated interface",
      "bs": "e-enable strategic applications"
    }
  },
  {
    "id": 4,
    "name": "Patricia Lebsack",
    "username": "Karianne",
    "email": "Julianne.OConner@kory.org",
    "address": {
      "street": "Hoeger Mall",
      "suite": "Apt. 692",
      "city": "South Elvis",
      "zipcode": "53919-4257",
      "geo": {
        "lat": "29.4572",
        "lng": "-164.2990"
      }
    },
    "phone": "493-170-9623 x156",
    "website": "kale.biz",
    "company": {
      "name": "Robel-Corkery",
      "catchPhrase": "Multi-tiered zero tolerance productivity",
      "bs": "transition cutting-edge web services"
    }
  },
  {
    "id": 5,
    "name": "Chelsey Dietrich",
    "username": "Kamren",
    "email": "Lucio_Hettinger@annie.ca",
    "address": {
      "street": "Skiles Walks",
      "suite": "Suite 351",
      "city": "Roscoeview",
      "zipcode": "33263",
      "geo": {
        "lat": "-31.8129",
        "lng": "62.5342"
      }
    },
    "phone": "(254)954-1289",
    "website": "demarco.info",
    "company": {
      "name": "Keebler LLC",
      "catchPhrase": "User-centric fault-tolerant solution",
      "bs": "revolutionize end-to-end systems"
    }
  },
  {
    "id": 6,
    "name": "Mrs. Dennis Schulist",
    "username": "Leopoldo_Corkery",
    "email": "Karley_Dach@jasper.info",
    "address": {
      "street": "Norberto Crossing",
      "suite": "Apt. 950",
      "city": "South Christy",
      "zipcode": "23505-1337",
      "geo": {
        "lat": "-71.4197",
        "lng": "71.7478"
      }
    },
    "phone": "1-477-935-8478 x6430",
    "website": "ola.org",
    "company": {
      "name": "Considine-Lockman",
      "catchPhrase": "Synchronised bottom-line interface",
      "bs": "e-enable innovative applications"
    }
  },
  {
    "id": 7,
    "name": "Kurtis Weissnat",
    "username": "Elwyn.Skiles",
    "email": "Telly.Hoeger@billy.biz",
    "address": {
      "street": "Rex Trail",
      "suite": "Suite 280",
      "city": "Howemouth",
      "zipcode": "58804-1099",
      "geo": {
        "lat": "24.8918",
        "lng": "21.8984"
      }
    },
    "phone": "210.067.6132",
    "website": "elvis.io",
    "company": {
      "name": "Johns Group",
      "catchPhrase": "Configurable multimedia task-force",
      "bs": "generate enterprise e-tailers"
    }
  },
  {
    "id": 8,
    "name": "Nicholas Runolfsdottir V",
    "username": "Maxime_Nienow",
    "email": "Sherwood@rosamond.me",
    "address": {
      "street": "Ellsworth Summit",
      "suite": "Suite 729",
      "city": "Aliyaview",
      "zipcode": "45169",
      "geo": {
        "lat": "-14.3990",
        "lng": "-120.7677"
      }
    },
    "phone": "586.493.6943 x140",
    "website": "jacynthe.com",
    "company": {
      "name": "Abernathy Group",
      "catchPhrase": "Implemented secondary concept",
      "bs": "e-enable extensible e-tailers"
    }
  },
  {
    "id": 9,
    "name": "Glenna Reichert",
    "username": "Delphine",
    "email": "Chaim_McDermott@dana.io",
    "address": {
      "street": "Dayna Park",
      "suite": "Suite 449",
      "city": "Bartholomebury",
      "zipcode": "76495-3109",
      "geo": {
        "lat": "24.6463",
        "lng": "-168.8889"
      }
    },
    "phone": "(775)976-6794 x41206",
    "website": "conrad.com",
    "company": {
      "name": "Yost and Sons",
      "catchPhrase": "Switchable contextually-based project",
      "bs": "aggregate real-time technologies"
    }
  },
  {
    "id": 10,
    "name": "Clementina DuBuque",
    "username": "Moriah.Stanton",
    "email": "Rey.Padberg@karina.biz",
    "address": {
      "street": "Kattie Turnpike",
      "suite": "Suite 198",
      "city": "Lebsackbury",
      "zipcode": "31428-2261",
      "geo": {
        "lat": "-38.2386",
        "lng": "57.2232"
      }
    },
    "phone": "024-648-3804",
    "website": "ambrose.net",
    "company": {
      "name": "Hoeger LLC",
      "catchPhrase": "Centralized empowering task-force",
      "bs": "target end-to-end models"
    }
  }
],
}

訪問http://localhost:8000/users

4 總結

按umi推薦的方式去創建目錄

注意約定名 pages目錄下的所有js都回被默認生成路由,可通過配置排出

省略了model的手動注冊,至于忽略namespace,我試了不行

各個page的model不能相互引用?不是很明白什么意思,我試了每個page都能獲取所有的state,并不是只能獲取屬于自己的。可能是我理解有誤。

沒有看出來umi的好處,只是目錄的區別嗎?

這個 issues 下有關于umi按page分的討論。https://github.com/sorrycc/bl...
希望知道umi核心優勢的小伙伴留言解釋下,前端菜鳥不是很懂。

別忘了關注我 mike啥都想搞

還有其他后端技術分享在我的公眾號。

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/100943.html

相關文章

  • 從項目中由淺入深的學習react (2)

    摘要:序列文章從項目中由淺入深的學習微信小程序和快應用前言從和原生兩個項目來介紹的使用搞懂這兩個項目上手擼代碼篇效果圖項目歡迎技術棧路由版本狀態管理組件字體適配方案適配技能點分析技能點對應的種定義組件方法函數式定義的無狀態組 showImg(https://segmentfault.com/img/bVbqPvN?w=820&h=512); 序列文章 從項目中由淺入深的學習vue,微信小程序...

    leap_frog 評論0 收藏0
  • Umi.js

    摘要:,中文可發音為烏米,是一個可插拔的企業級應用框架。以路由為基礎的,支持類的約定式路由,以及各種進階的路由功能,并以此進行功能擴展,比如支持路由級的按需加載。全局存于目錄,所有頁面都可引用頁面不能被其他頁面所引用。 umi,中文可發音為烏米,是一個可插拔的企業級 react 應用框架。umi 以路由為基礎的,支持類 next.js 的約定式路由,以及各種進階的路由功能,并以此進行功能擴展...

    30e8336b8229 評論0 收藏0

發表評論

0條評論

最新活動
閱讀需要支付1元查看
  • <ul id="a02sk"></ul><strike id="a02sk"><input id="a02sk"></input></strike><fieldset id="a02sk"><menu id="a02sk"></menu></fieldset>
    <strike id="a02sk"><input id="a02sk"></input></strike>
  • <strike id="a02sk"></strike>
    <fieldset id="a02sk"><table id="a02sk"></table></fieldset>
    <strike id="a02sk"></strike>
  • <