1:最流行的开源react ui组件库

  1.1:material-ui(国外)

  1.2:ant-design(推荐:国内蚂蚁金服)

2.如何使用

  方式一(页面引入):

    在<head>标签内加入 <meta name = "viewport" content="width-device-width, initial-scale-1, maximum-scale=1, minimum-scale=1, user-scalable=no"/>

    <script src="https://as.alipayobjects.com/g/component/fastclick/1.0.6/fastclick.js"</script>(解决移动端点击监听300毫秒延迟问题)

  方式二(推荐):

    npm install antd-mobile --save

  

3.强烈推荐按需打包

  import {Button, Toast} from 'antd-mobile' 的方式打包的话会将所有的antd-mobile打包

  babel-plugin import(推荐,只加载import需要的模块)

  如何使用 babel-plugin import:

    1)npm install react-app-rewired@1.4.0 babel-plugin-import@1.6.3 --save-dev

    (因为是编译打包的工具包,而不是运行时的依赖,所以-dev)(不能超过2.0版本,超过2.0版本会报错!!!)

    2)与package.json同级创建 config-overrides.js

      

const {injectBabelPlugin} = require('react-app-rewired');
module.exports = function override(config, evn) {
    config = injectBabelPluugin(['import', {libraryName: 'antd-mobile', style: 'css'}], cinfig);
    return config;
};

    3)将原来的package.json中的scripts内容全部替换掉,放入下面的scripts

    

    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test --env=jsdom"

     

4.代码如下:

index.js

import React from 'react'
import {render} from 'react-dom'

import App from './components/app'
// import 'antd-mobile/dist/antd-mobile.css'/*将antd所有样式引入*/

render(<App/>, document.getElementById('root'));

app.jsx

import React, {Component} from 'react'
import {Button, Toast} from 'antd-mobile'

export default class App extends Component {
    handleClick = () => {
        Toast.info('提交成功');
    }

    render() {
        return (
            <div>
                <Button type='primary' onClick={this.handleClick}>提交</Button>
            </div>
        )
    }
}

package.json

{
  "name": "react_blank",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "antd-mobile": "^2.2.11",
    "react": "^16.2.0",
    "react-dom": "^16.2.0"
  },
  "devDependencies": {
    "babel-plugin-import": "^1.6.3",
    "react-app-rewired": "^1.4.0",
    "react-scripts": "^1.1.0"
  },
  "scripts": {
    "start": "react-app-rewired start",
    "build": "react-app-rewired build",
    "test": "react-app-rewired test --env=jsdom"
  }
}

config-overrides.js

const {injectBabelPlugin} = require('react-app-rewired');
module.exports = function override(config, env) {
    config = injectBabelPlugin(['import', {libraryName: 'antd-mobile', style: 'css'}], config);
    return config;
};

      

36_react_ui_antd的更多相关文章

随机推荐

  1. C语言 基础

    内存的定义 在学习python的时候 了解过内存的管理机制,例如引用计数,垃圾回收,小内存池的概念. 但是并不了解内存究竟是个什么东西?不了解内存的实际存储方式. Mac OS Mojave 处理器 ...

  2. Python3 多线程例子

    import threading, zipfile class AsyncZip(threading.Thread): def __init__(self, infile, outfile): thr ...

  3. java-log4j日志打印

    参考路径: https://blog.csdn.net/edward0830ly/article/details/8250412 https://www.cnblogs.com/ITtangtang/ ...

  4. 记不住 Linux 命令?这三个工具可以帮你(转)

    链接:https://zhuanlan.zhihu.com/p/30668155 Linux 桌面从开始的简陋到现在走了很长的路.在我早期使用 Linux 的那段日子里,掌握命令行是最基本的 —— 即 ...

  5. 【转】Mysql索引设计原则

    来源:https://segmentfault.com/a/1190000000473085 假设一高频查询如下SELECT * FROM user WHERE area='amoy' AND sex ...

  6. 编辑器-vim

    编辑器之神-vim vi简介 vi是“Visual interface”的简称,它在Linux上的地位就仿佛Edit程序在DOS上一样.它可以执行输出.删除.查找.替换.块操作等众多文本操作,而且用户 ...

  7. 联想IDEAPAD 320C-15笔记本显卡驱动问题

    联想IDEAPAD 320C-15笔记本显卡驱动问题核显Intel(R) HD Graphics 620独显AMD Radeon(TM) 530必须安装好核显驱动,独显驱动才能正常工作,否则设备管理器 ...

  8. close_wait状态和time_wait状态(TCP连接)

    1.CLOSE_WAIT的简单解决方案 不久前,我的Socket Client程序遇到了一个非常尴尬的错误.它本来应该在一个socket长连接上持续不断地向服务器发送数据,如果socket连接断开,那 ...

  9. 配置RIPng(PT)

    一:拓扑图 二:配置过程 1:首先为pc0:pc1: pc2 配置IPv6地址(注意标明前缀),可以手动配置也可以自动获取. 手动配置 自动获取 2:给路由器配置RIPng协议 全局开启RIPng协议 ...

  10. vue 路由参数

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...