自定义颜色选择功能
2026/6/23 19:09:51 网站建设 项目流程

开箱即用

1.效果:

2.代码

<template> <div class="snowy-color-picker" @click="forceResize"> <color-picker v-bind="$attrs" format="hex" :pureColor="props.value" @update:pureColor="update" /> </div> </template> <script setup> import { ColorPicker } from 'vue3-colorpicker' import 'vue3-colorpicker/style.css' const emit = defineEmits(['update:value']) const props = defineProps({ value: { type: String, default: '#1677FF' } }) const forceResize = () => { window.dispatchEvent(new Event('resize')) } const update = (val) => { showTxt(val) emit('update:value', val) } onMounted(() => { showTxt(props.value) }) const showTxt = (val) => { const currentColor = document.querySelector('.current-color') if (currentColor) { currentColor.textContent = val } } </script> <style lang="less"> .snowy-color-picker { .vc-color-wrap { width: auto; } .current-color { color: #fff; padding: 0 10px; } } </style>

使用:

<color-picker v-model:value="formData.color" />

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询