1.导入插件及配置
#从uni-app插件市场搜索colorUi,下载地址👉https://ext.dcloud.net.cn/plugin?id=239
![](https://i-blog.csdnimg.cn/blog_migrate/5835f6cbefd03178f04137e39676ede3.png)
导入插件到项目中或者下载插件压缩包
![](https://i-blog.csdnimg.cn/blog_migrate/bcf54cbf7bef228c5479b855c0d3608e.png)
下载插件压缩包的,将压缩包解压后的colorui文件夹复制到项目根目录下;导入插件不用进行此步操作。
![](https://i-blog.csdnimg.cn/blog_migrate/faa34af2f3c8867d421163c8d0db9006.png)
App.vue 引入关键Css main.css
icon.css
<style>
@import "colorui/main.css";
@import "colorui/icon.css";
</style>
2.使用colorUi里的组件
使用教程 https://ext.dcloud.net.cn/plugin?id=239
导航栏
使用colorUi里的导航栏,需要在 App.vue 进行如下配置:
<script>
import Vue from 'vue'
export default {
onLaunch: function() {
console.log('App Launch')
uni.getSystemInfo({
success: function(e) {
// #ifndef MP
Vue.prototype.StatusBar = e.statusBarHeight;
if (e.platform == 'android') {
Vue.prototype.CustomBar = e.statusBarHeight + 50;
} else {
Vue.prototype.CustomBar = e.statusBarHeight + 45;
};
// #endif
// #ifdef MP-WEIXIN
Vue.prototype.StatusBar = e.statusBarHeight;
let custom = wx.getMenuButtonBoundingClientRect();
Vue.prototype.Custom = custom;
Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
// #endif
// #ifdef MP-ALIPAY
Vue.prototype.StatusBar = e.statusBarHeight;
Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
// #endif
}
})
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
}
}
</script>
<style>
/*每个页面公共css */
@import "colorui/main.css";
@import "colorui/icon.css";
</style>
pages.json 配置取消系统导航栏
"globalStyle": {
"navigationStyle": "custom"
},
在main.js 引入 cu-custom 组件
import cuCustom from './colorui/components/cu-custom.vue'
Vue.component('cu-custom',cuCustom)
在html页面直接复制组件代码过去即可,如 index.vue
<cu-custom bgColor="bg-gradual-blue" :isBack="true">
<block slot="backText">返回</block>
<block slot="content">导航栏</block>
</cu-custom>
底部导航栏使用
项目目录:
![](https://i-blog.csdnimg.cn/blog_migrate/71e75477a3b1e026777b3501b9b2f9cf.png)
index.vue
<template>
<view class="">
<basics v-if=" PageCur=='basics' "></basics>
<me v-if=" PageCur=='me' "></me>
<view class="cu-bar tabbar bg-black foot">
<view class="action" @click="NavChange" data-cur="basics">
<view class="cuIcon-homefill" :class="PageCur=='basics'?'text-orange':'text-gray'"></view>
<view :class="PageCur=='basics'?'text-orange':'text-gray'">首页</view>
</view>
<view class="action" @click="NavChange" data-cur="me">
<view class="cuIcon-my" :class="PageCur=='me'?'text-orange':'text-gray'"></view>
<view :class="PageCur=='me'?'text-orange':'text-gray'">我的</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
PageCur: 'basics'
}
},
onLoad() {
},
methods: {
NavChange: function(e) {
this.PageCur = e.currentTarget.dataset.cur
}
}
}
</script>
<style scoped lang="scss">
</style>
/basics/home.vue
<template name="basics">
<view class="">
<cu-custom bgColor="bg-orange" :isBack="false">
<block slot="content">首页</block>
</cu-custom>
</view>
</template>
<script>
export default {
name:'basics'
}
</script>
<style>
</style>
/me/home.vue
<template name="me">
<view class="">
<cu-custom bgColor="bg-orange" :isBack="false">
<block slot="content">个人中心</block>
</cu-custom>
</view>
</template>
<script>
export default {
name:'me'
}
</script>
<style>
</style>
main.js 注册组件
import basics from './pages/basics/home.vue'
Vue.component('basics',basics)
import me from './pages/me/home.vue'
Vue.component('me',me)
效果图如下:
![](https://i-blog.csdnimg.cn/blog_migrate/bd3aa261b6d19c0b4769e3e73095ae95.png)
其他的组件也是复制代码,直接使用。