84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
I want to use predefined variables in my Vue 3 component.
Du musst noch ein Bild aufnehmen!
Unfortunately, I get the error "SassError: Undefined variable.". What do I have to import to use Vuetify's global variables?
The use of these colors is notsostraightforward.
Recorded herehttps://vuetifyjs.com/en/function/sass-variables/#webpack-installNoteRequires sass-loader@^7.0.0and change webpack configuration
Requires sass-loader@^7.0.0
You can also skip this if you import color variables in the component file (the number of../may vary)
../
@import '../../node_modules/vuetify/src/styles/settings/_colors.scss';
The next thing to remember is the structure of the object
Here is an excerpt
$red: () !default; $red: map-deep-merge( ( 'base': #F44336, 'lighten-5': #FFEBEE, 'lighten-4': #FFCDD2, 'lighten-3': #EF9A9A, 'lighten-2': #E57373, 'lighten-1': #EF5350, 'darken-1': #E53935, 'darken-2': #D32F2F, 'darken-3': #C62828, 'darken-4': #B71C1C, 'accent-1': #FF8A80, 'accent-2': #FF5252, 'accent-3': #FF1744, 'accent-4': #D50000 ), $red ); /* other colors... */ $colors: () !default; $colors: map-deep-merge( ( 'red': $red, 'pink': $pink, 'purple': $purple, 'deep-purple': $deep-purple, 'indigo': $indigo, 'blue': $blue, 'light-blue': $light-blue, 'cyan': $cyan, 'teal': $teal, 'green': $green, 'light-green': $light-green, 'lime': $lime, 'yellow': $yellow, 'amber': $amber, 'orange': $orange, 'deep-orange': $deep-orange, 'brown': $brown, 'blue-grey': $blue-grey, 'grey': $grey, 'shades': $shades ), $colors );
So colors don't map to strings, but to objects (seemap-deep-merge), so you can't use$redto give you the color value.
map-deep-merge
$red
Instead, you can use themap-deep-getfunction to get the base red
map-deep-get
.class{ background: map-deep-get($colors, "red", "base"); /* OR */ background: map-get($red, "base"); }
So it looks like this
The use of these colors is notsostraightforward.
Recorded herehttps://vuetifyjs.com/en/function/sass-variables/#webpack-installNote
Requires sass-loader@^7.0.0
and change webpack configurationYou can also skip this if you import color variables in the component file (the number of
../
may vary)The next thing to remember is the structure of the object
Here is an excerpt
So colors don't map to strings, but to objects (see
map-deep-merge
), so you can't use$red
to give you the color value.Instead, you can use the
map-deep-get
function to get the base redSo it looks like this