「uni-app 组件」t-color-picker 颜色选择器

2019-05-18  本文已影响0人  程序员永不秃头

注意:此组件在性能较差的手机上,可能表现不是很理想,低配置手机请慎重使用。

github 地址: https://github.com/mehaotian/t-color-picker
插件市场地址:http://ext.dcloud.net.cn/plugin?id=412

我们在开发 web 应用的时候,想选择颜色,直接使用 <input type="color"> 即可, 然而在 uni-app 中并没有选择器,需要我们去实现相关功能。

此组件基本全平台支持。(支付宝,百度,头条小程序理论上都支持,但是没有很细致的测试这几个平台)

功能亮点

未实现

效果演示

color-picker.gif

调用方式

代码示例


<template>
    <view>
        <t-color-picker></t-color-picker>
    </view>
</template>
<script>
    import tColorPicker from '@/components/t-color-picker/t-color-picker.vue'
    export default {
        components: {
            tColorPicker
        }
    };
</script>

属性说明

属性名 类型 默认值 说明
color Object {r: 0,g: 0,b: 0,a: 1} 颜色选择器初始颜色
spare-color Object 备选色,格式为:[ {r: 0,g: 0,b: 0,a: 1}]
confirm function 确认选择函数 ,返回值:event = {rgba:{r: 0,g: 0,b: 0,a: 1},hex:'#000000'}

事件说明

open()

打开颜色选择器,需要 t-color-picker 中声明 ref 属性

完整使用示例



<template>
    <view class="t-page">
        <button @click="open">打开颜色选择器</button>
        <!-- 需要声明 ref  -->
        <t-color-picker ref="colorPicker" :color="color" @confirm="confirm"></t-color-picker>
    </view>
</template>
<script>
    import tColorPicker from '@/components/t-color-picker/t-color-picker.vue'
    export default {
        components: {
            tColorPicker
        },
        data() {
            return {
                color: {r: 255,g: 0,b: 0,a: 0.6}
            };
        },
        methods: {
            open(item) {
                // 打开颜色选择器
                this.$refs.colorPicker.open();
            },
            confirm(e) {
                console.log('颜色选择器返回值:'+ e)
            }
        }
    };
</script>


更新日志

v1.0.0

上一篇 下一篇

猜你喜欢

热点阅读