注意:此組件在性能較差的手機上,可能表現不是很理想,低配置手機請慎重使用。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>
複製代碼