GithubHelp home page GithubHelp logo

Comments (2)

kleinfreund avatar kleinfreund commented on June 13, 2024

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.

NeroN7F avatar NeroN7F commented on June 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.