Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report