Vue 自定義ColorPicker及使用方法
Vue 自定義ColorPicker

創(chuàng)建自定義組件ColorPicker.vue
<template>
<div class="box">
<div class="picker-box">
<div class="color" :style="{ background: color }"></div>
<div class="el-icon-arrow-down"></div>
</div>
<el-color-picker
v-model="color"
show-alpha
class="elcolorpicker"
@change="colorChange"
></el-color-picker>
</div>
</template>
<script>
export default {
model: {
prop: "myColor",
event: "change",
},
props: {
myColor: [String, Number],
},
data() {
return {
color: "#000",
};
},
watch: {
myColor: {
handler(newVal, oldVal) {
this.color = newVal || "#000000";
},
},
},
mounted() {
this.color = this.myColor || "#000000";
},
methods: {
colorChange(color) {
this.color = color;
this.$emit("change", color);
},
},
};
</script>
<style lang="less" scoped>
.box {
position: relative;
}
.picker-box {
width: 84px;
height: 23px;
background: #fff;
border-radius: 4px;
border: 1px solid #dcdfe6;
padding: 0 10px;
display: flex;
justify-content: space-between;
align-items: center;
.color {
width: 13px;
height: 13px;
box-shadow: inset 0 0 0 0.013333rem rgba(0, 0, 0, 0.15);
}
}
.elcolorpicker {
position: absolute;
opacity: 0;
left: 0;
top: 0;
}
/deep/.el-color-picker {
height: 100%;
width: 100%;
}
/deep/.el-color-picker__trigger {
width: 100%;
height: 100%;
border: 0px solid #e6e6e6;
border-radius: 4px;
}
</style>使用
導(dǎo)入,掛載步驟省略
<ColorPicker v-model="titleColor" @change="handleChange" />
到此這篇關(guān)于Vue 自定義ColorPicker的文章就介紹到這了,更多相關(guān)Vue 自定義ColorPicker內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue3+el-select實現(xiàn)觸底加載更多功能(ts版)
這篇文章主要給大家介紹了基于vue3和el-select實現(xiàn)觸底加載更多功能,文中有詳細(xì)的代碼示例,感興趣的同學(xué)可以借鑒參考下2023-07-07
Vue全局共享數(shù)據(jù)之globalData,vuex,本地存儲的使用
這篇文章主要介紹了Vue全局共享數(shù)據(jù)之globalData,vuex,本地存儲的使用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-10-10
使用ElementUI中el-upload上傳文件轉(zhuǎn)base64格式
這篇文章主要介紹了使用ElementUI中el-upload上傳文件轉(zhuǎn)base64格式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-05-05
webpack vue 項目打包生成的文件,資源文件報404問題的修復(fù)方法(總結(jié)篇)
這篇文章主要介紹了解決webpack vue 項目打包生成的文件,資源文件報404問題的修復(fù)方法,需要的朋友可以參考下2018-01-01
vue子組件如何獲取父組件的內(nèi)容(props屬性)
這篇文章主要介紹了vue子組件獲取父組件的內(nèi)容(props屬性),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04

