Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem that scss variables can't be parsed?

Shulou Source: shulou.com Published: 2022-06-01 05:16:30 10月03日 Update

This article mainly introduces the relevant knowledge of "scss variable resolution can not be solved", the editor shows you the operation process through the actual case, the operation method is simple and fast, practical, I hope this "scss variable resolution can not be solved" article can help you solve the problem.

The problem that the scss variable cannot be parsed is embarrassing. We all know that the scss variable is defined as follows

$width: "100px"

When I use it normally, it should be as follows:

.box {

Width: $width

}

Yes, there is no problem with referencing variables above.

Now let's see what's wrong with us today.

/ / follow the change of skin

@ mixin bg-theme-image ($url) {

@ each $theme-name, $theme-map in $themes {

.theme-# {"" + $theme-name} & {

Background: url ($url + "-" + $theme-name + ".png") no-repeat

Background-size: 100%

@ media (- webkit-min-device-pixel-ratio: 2), (min-device-pixel-ratio: 2) {

Background: url ($url + "-" + $theme-name + "- 2x.png") no-repeat

Background-size: 100%

}

@ media (- webkit-min-device-pixel-ratio: 3), (min-device-pixel-ratio: 3) {

Background: url ($url + "-" + $theme-name + "- 3x.png") no-repeat

Background-size: 100%

}

}

}

}

The above $theme-name cannot be parsed, and there is no problem with the local npm run dev, but? When I was in npm run build, I reported an error. The package was not successful, which is the reason why this variable could not be parsed. As a result, Lujin could not find the corresponding url path.

Modify it as follows:

/ / follow the change of skin

@ mixin bg-theme-image ($url) {

@ each $theme-name, $theme-map in $themes {

.theme-# {"" + $theme-name} & {

Background: url ($url + "-" + # {$theme-name} + ".png") no-repeat

Background-size: 100%

@ media (- webkit-min-device-pixel-ratio: 2), (min-device-pixel-ratio: 2) {

Background: url ($url + "-" + # {$theme-name} + "- 2x.png") no-repeat

Background-size: 100%

}

@ media (- webkit-min-device-pixel-ratio: 3), (min-device-pixel-ratio: 3) {

Background: url ($url + "-" + # {$theme-name} + "- 3x.png") no-repeat

Background-size: 100%

}

}

}

}

Add # {$theme-name} to $theme-name to parse this variable and there will be no error and no problem with packaging.

The problem of scss # {} interpolation is summarized as follows

Generally, the variables we define are attribute values and can be used directly, but if the variable is used as an attribute or in some special cases, it must be used in the form of # {$variables}.

$borderDirection: top! default

$baseFontSize: 12px! default

$baseLineHeight: 1.50! default

/ / apply to class and attributes

.border-# {$borderDirection} {

Border-# {$borderDirection}: 1px solid # ccc

}

/ / apply to complex attribute values

Body {

Font:# {$baseFontSize} / # {$baseLineHeight}

}

This is the end of the content about "the resolution of scss variables can not be solved". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Variables problems attributes knowledge time industry application different complex practical special awkward successful content reason practicality that is form situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple NVidia MariaDB OPPO Reno vpn