[每天進步一點點~] uni-app colorUi使用教程

1.導(dǎo)入插件及配置

#從uni-app插件市場搜索colorUi,下載地址??https://ext.dcloud.net.cn/plugin?id=239

導(dǎo)入插件到項目中或者下載插件壓縮包

下載插件壓縮包的,將壓縮包解壓后的colorui文件夾復(fù)制到項目根目錄下;導(dǎo)入插件不用進行此步操作。

App.vue 引入關(guān)鍵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

導(dǎo)航欄

使用colorUi里的導(dǎo)航欄,需要在 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 配置取消系統(tǒng)導(dǎo)航欄

"globalStyle": {
    "navigationStyle": "custom"
},

在main.js 引入 cu-custom 組件

import cuCustom from './colorui/components/cu-custom.vue'
Vue.component('cu-custom',cuCustom)

在html頁面直接復(fù)制組件代碼過去即可,如 index.vue

<cu-custom bgColor="bg-gradual-blue" :isBack="true">
    <block slot="backText">返回</block>
    <block slot="content">導(dǎo)航欄</block>
</cu-custom>

底部導(dǎo)航欄使用

項目目錄:


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)

效果圖如下:


其他的組件也是復(fù)制代碼,直接使用。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容