[Vue] The difference between CSS and CSS modules Scoped

Source: Internet
Author: User

is a solution to the CSS global scope problem (style conflict (pollution)). 1.Scoped CSS

When a <style> tag has an scoped attribute, it is equivalent to adding a unique attribute to the element to differentiate it .

 <  style  scoped  >  .example {color:red;}  </ style  >  <  template   >  <  div  class  = "Example"  >  hi</ div  >  </ template  >  

< style > . example[data-v-f3f3eg9] {  color:red;} </ style > < Template >  <  class= "Example"  data-v-f3f3eg9>hi</ Div > </ Template >
2.CSS Modules

by give the style name a hash string suffix , Implementing a style-compiled style in a specific scope context is globally unique.

 <  template  >  <  p  :class  = "$style. Gray"  >   Im Gray  </ p  >  </ template  >  <  style  module  >  .gray {color:gray;}  </ style  >  

The results of using the module are compiled as follows:

<class= "Gray_3fi3s6uz">Im Gray</p>  . Gray_3fi3s6uz {color:gray;}

Thus, the CSS module directly replaces the class name, excluding the possibility of user setting the class name affecting the component style.

Recommended use of CSS Modules

See the Official document: https://vue-loader.vuejs.org/zh/guide/scoped-css.html# mixed local and global styles

[Vue] The difference between CSS and CSS modules Scoped

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.