1.导入插件及配置
#从uni-app插件市场搜索colorUi,下载地址👉https://ext.dcloud.net.cn/plugin?id=239
导入插件到项目中或者下载插件压缩包
下载插件压缩包的,将压缩包解压后的colorui文件夹复制到项目根目录下;导入插件不用进行此步操作。
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>
底部导航栏使用
项目目录:
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)
效果图如下:
其他的组件也是复制代码,直接使用。