最近要写后台前端代码(公司是缺什么学什么),网上找了一圈发现最近流行用一个很好用的东西:ant-design。支付宝团队出的,然后各种周边antd mobile,umi,dva.等等。这个有兴趣的同志自己去找找看.这边重点介绍:antd mobile -rn。(官方已经宣布不再维护了,但是用起来很好用)。
因为我移动端使用的是reactNative,所以就使用了这个。
集成dva,自己找了半天资料,折腾了半天,无意中发现官方居然已经有这个东西了:
https://github.com/nihgwu/react-native-dva-starter
连接点过去你就都明白了。
1.创建一个已经集成好dva的框架,
npm install dva-native-cli -g
dvanative git app
cd app
2.新建完项目后,集成antd组件库:
$ npm install antd-mobile-rn --save
//用于实现按需加载
$ npm install babel-plugin-import --save-dev
3.找到:. babelrc文件 添加如下:
{
"presets": ["react-native"],
"plugins": ["transform-decorators-legacy",[
"import",
{
"libraryName": "antd-mobile-rn"
}
]]
}
4.使用:
//注意这个import 要放在import React, { Component } from 'react' 下面,其他import前面
import { Button } from 'antd-mobile-rn';
render() {
return (
<Button>登录</Button>
)
}
好了,这样就可以轻松加愉快的使用dva和antd组件库啦。
网友评论