本项目已停止维护
Mina Component 是一个微信 小程序组件库。
使用 npm 构建前,请先阅读微信官方的 npm 支持
# 通过 npm 安装
npm i mina-component -S --production
# 通过 yarn 安装
yarn add mina-component --production
# 安装 0.x 版本
npm i mina-component -S --production
打开微信开发者工具,点击 工具 -> 构建 npm,并勾选 使用 npm 模块 选项,构建完成后,即可引入组件。
如果你使用 typescript 开发小程序,还需要做如下操作,以获得顺畅的开发体验。
# 通过 npm 安装
npm i -D miniprogram-api-typings
# 通过 yarn 安装
yarn add -D miniprogram-api-typings
请将path/to/node_modules/mina-component
修改为项目的 node_modules
中 mina-component 所在的目录。
{
...
"compilerOptions": {
...
"baseUrl": ".",
"types": ["miniprogram-api-typings"],
"paths": {
"mina-component/*": ["path/to/node_modules/mina-component/dist/*"]
},
"lib": ["ES6"]
}
}
以 ImagePreview 组件为例,只需要在app.json
或index.json
中配置 ImagePreview 对应的路径即可。
所有组件文档中的引入路径均以 npm 安装为例,如果你是通过下载源代码的方式使用 mina-component,请将路径修改为项目中 mina-component 所在的目录。
// 通过 npm 安装
// app.json
"usingComponents": {
"mina-image-preview": "mina-component/image-preview/index"
}
// 通过下载源码使用 es6版本
// app.json
"usingComponents": {
"mina-image-preview": "path/to/mina-component/dist/image-preview/index"
}
// 通过下载源码使用 es5版本
// app.json
"usingComponents": {
"mina-image-preview": "path/to/mina-component/lib/image-preview/index"
}
引入组件后,可以在 wxml 中直接使用组件
<mina-image-preview
id="J-preview"
catch:onClose="handleClosePreview"
catch:onChange="handlePreviewChange"
/>
# 将项目克隆到本地
git clone [email protected]:yw0525/mina-component.git
# 安装项目依赖
cd mina-component && npm install
# 执行组件编译
npm run dev
接着打开微信开发者工具,导入example
目录的项目就可以预览示例了。
本项目基于 MIT 协议,请自由地享受和参与开源。