Comments (2)
For showing the currently selected color in another place of a component, you can use the color-change
event.
Letβs say you have a Vue component using the color picker like so:
<template>
<ColorPicker
color="#ff8800"
@color-change="setColor"
/>
<div
class="color-preview"
style="background-color: #ff8800;"
/>
</template>
you can use the color-change
event to call a method of your component (here, I called it setColor
). With it, you can set a data property in your component:
import { ColorPicker } from 'vue-accessible-color-picker';
export default {
name: 'MyComponent',
components: {
ColorPicker,
},
data() {
return {
currentColor: '#ff8800',
}
},
methods: {
setColor(colorData) {
this.currentColor = colorData.colors.hex
},
},
}
in your component, you can then preview the color like this:
<template>
<ColorPicker
:color="currentColor"
@color-change="setColor"
/>
<div
class="color-preview"
:style="`background-color: ${currentColor};`"
/>
</template>
Make sure you size the div
element so that it has dimensions (e.g. by setting width
and height
on the .color-preview
class).
Does that help you?
from vue-accessible-color-picker.
Thank you
Seems I screwed before
<ColorPicker :color="color.color" :visible-formats="['hex', 'rgb']" default-format="hex" alpha-channel="hide" @color-change="updateColor"/>
<span v-bind:style="color">f1</span>
methods:{
updateColor (eventData) {
this.color = JSON.parse(eventData)
}
}
Your solution much better
from vue-accessible-color-picker.
Related Issues (16)
- Device-independent colors: Add Lab and LCH formats HOT 1
- Provide untranspiled ES module bundles HOT 1
- Disable alpha chanel HOT 4
- Clicking in color space does not always select a color HOT 3
- [Error][TS]Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. HOT 1
- Alpha channel in HEX HOT 8
- Alpha channel hidden, alpha channel still visible in HEX Color Input HOT 2
- Test coverage reporting in pull requests & readme badge HOT 2
- Basic install doesn't work HOT 2
- Incorrect initialization if color is white HOT 1
- :visible-formats="['hex']" does not work HOT 2
- The automated release is failing π¨ HOT 1
- Migrate to Vue.js 3 HOT 1
- Types for typescript HOT 2
- Remove typescript development dependency with upcoming vue-jest release HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-accessible-color-picker.