牧马找房 CMS 正式上线
ColorUI GA 使用示例
简介
- • ColorUI GA 是基于ColorUI 2.0开发的轻量、可靠的小程序原生css组件库,理论上适用于其他支持css库的所有平台。更多UI模板请查看小程序或下载源码运行:https://github.com/XiaokangLei/ColorUI-GA
- • 使用文档地址:https://xiaokanglei.github.io/ColorUI-GA-Docs/#/
组件库引入
以表单组件为例介绍详细使用ColorUI GA小程序原生组件库的详细步骤,Demo下载地址https://github.com/XiaokangLei/ColorUI-GA/releases/download/v2.0.9/demo.zip
一、创建新项目
若在已有项目中引入组件库,请忽略步骤1,直接跳转到步骤2
- • 填写项目名称、空目录路径、APPID,开发模式选择小程序
- • 根据项目需要,选择【微信云开发】或者【不使用云服务】,示例不使用云开发,选者【不使用云服务】
- • 模板选择,选择【JavaScript-基础模板】,点击确定
- • 进入小程序,创建的基础小程序如下图所示
- • 若出现
.js无法被其他模块引入等错误
- • 修改
project.config.json中的setting属性增加"ignoreDevUnusedFiles": false和"ignoreUploadUnusedFiles": false,这是由于部分组件未使用导致,后期可直接移除相关代码
二、引入组件库
- • 在全局样式文件
app.wxss中引入关键css:main.wxss,icon.wxss
/* 根目录 app.wxss 文件 */
@import "colorui/main.wxss";
@import "colorui/icon.wxss";
/* 若需要使用微动画,请引入 animation.wxss */
@import "colorui/animation.wxss";
/* 若使用暗色模式,请引入 dark.wxss,注意,当前版本暗色模式随系统切换,目前不支持手动切换 */
@import "colorui/dark.wxss";
- • 默认的新版基础组件
"style": "v2"会导致部分样式将失效,删除全局app.json里面的"style": "v2"。如确实需要使用新版样式,可在局部page中的.json文件中添加"style": "v2"。
- • 在
page中的.wxml文件中即可使用样式
三、自定义顶部导航栏(可选)
根据项目需要,决定是否自定义导航栏,示例导航栏代码在/colorui/components/cu-custom中,可自行修改相关参数进行配置。
- • 1、
app.js获得系统信息
onLaunch: function() {
wx.getSystemInfo({
success: e => {
this.globalData.StatusBar = e.statusBarHeight;
let custom = wx.getMenuButtonBoundingClientRect();
this.globalData.Custom = custom;
this.globalData.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
}
})
},
- • 2、
app.json配置取消系统默认导航栏,并全局引入组件
"window": {
"navigationStyle": "custom"
},
"usingComponents": {
"cu-custom":"/colorui/components/cu-custom/cu-custom"
}
- • 3、
xxx.wxml页面调用
<cu-custom bgColor="bg-gradual-pink" isBack="{{true}}">
<view slot="backText">返回</view>
<view slot="content">导航栏</view>
</cu-custom>
- • 4、参数
| 参数 | 作用 | 类型 | 默认值 |
| bgColor | 背景颜色类名 | String | '' |
| isBack | 是否开启返回 | Boolean | false |
| isCustom | 是否开启左侧胶囊 | Boolean | false |
| bgImage | 背景图片路径 | String | '' |
| isLucency | 背景透明 | Boolean | false |
| slot块 | 作用 | ||
| backText | 返回时的文字 | ||
| content | 中间区域 | ||
| right | 右侧区域(胶囊占位可使用范围很窄!) |
- • 5、示例
喜欢作者
2人喜欢