Vue3, Vite, Less, JS
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>
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:
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']
}
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
}
Thanks in advance!