1 下包 npm install antd-mobile --save
2 页面处理: index.html (官网上有)
<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>
<script>
if ('addEventListener' in document) {
document.addEventListener('DOMContentLoaded', function() {
FastClick.attach(document.body);
}, false);
}
if(!window.Promise) {
document.writeln('<script src="https://as.alipayobjects.com/g/component/es6-promise/3.2.2/es6-promise.min.js"'+'>'+'<'+'/'+'script>');
}
</script>
3 实现按需打包
1 下包 npm install --save-dev babel-plugin-import react-app-rewired
2 定义加载配置的js模块: 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;
}
3 修改配置: package.json
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test --env=jsdom",
"eject": "react-scripts eject"
}
4 使用
import {Button} from 'antd-mobile'
网友评论