注意:此组件在性能较差的手机上,可能表现不是很理想,低配置手机请慎重使用。javascript
github 地址: https://github.com/mehaotian/t-color-pickerhtml
插件市场地址:http://ext.dcloud.net.cn/plugin?id=412vue
咱们在开发 web
应用的时候,想选择颜色,直接使用 <input type="color">
便可, 然而在 uni-app
中并无选择器,须要咱们去实现相关功能。java
此组件基本全平台支持。(支付宝,百度,头条小程序理论上都支持,可是没有很细致的测试这几个平台)git
功能亮点github
未实现web
效果演示 小程序
代码示例app
<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'} |
打开颜色选择器,须要 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>
复制代码