Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

300
Visualizações
Cannot get the object value by parameter in Less Plugin function

Tech

Vue3, Vite, Less, JS

Background

Hi all, I am writing a Less Plugin function in my Vue3 project. The function is to get the color code from a color object by the key parameter.

The Less Plugin file:

 getColor: function (key) {
  const COLORS = {
    'white-opa-03': 'rgba(255, 255, 255, 0.3)',
    'white-opa-04': 'rgba(255, 255, 255, 0.4)',
    'black-opa-045': 'rgba(0, 0, 0, 0.45)',
    'black-opa-065': 'rgba(0, 0, 0, 0.65)',
  }
  return COLORS[key]
}

How I called the plugin function

<style lang="less" scoped">
@plugin '../../../public/assets/style/plugins/color.js';

.label {
  color: getColor('black-opa-045');
}

</style>

The Problem

However, in the browser, it did not return the color code successfully, but remains to show the complete function call. browser result

What I have tried:

  • When I tried to hard-code in the getColor function to make it get from a specific color instead of using the key parameter, it works.
     getColor: function (key) {
      const COLORS = {
        'white-opa-03': 'rgba(255, 255, 255, 0.3)',
        'white-opa-04': 'rgba(255, 255, 255, 0.4)',
        'black-opa-045': 'rgba(0, 0, 0, 0.45)',
        'black-opa-065': 'rgba(0, 0, 0, 0.65)',
      }
      return COLORS['black-opa-045']
    }
  • There seems no problem with the key parameter - I tried to return it like below and the value is "black-opa-025"
     getColor: function (key) {
      const COLORS = {
        'white-opa-03': 'rgba(255, 255, 255, 0.3)',
        'white-opa-04': 'rgba(255, 255, 255, 0.4)',
        'black-opa-045': 'rgba(0, 0, 0, 0.45)',
        'black-opa-065': 'rgba(0, 0, 0, 0.65)',
      }
      return key
    }

Notes

  • there are reason I don't store the color code in less is for single source of color code, that is shareable by both js & css files.

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda