[每天进步一点点~] uni-app colorUi使用教程

本文介绍了如何在uni-app中导入并使用colorUi插件,包括设置全局样式、创建导航栏和底部导航栏。通过具体步骤和代码示例,展示了如何在不同页面引入组件,实现自定义导航栏和底部导航栏的功能,帮助开发者快速搭建APP界面。
摘要由CSDN通过智能技术生成

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)

效果图如下:

其他的组件也是复制代码,直接使用。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值