vue-loader<\/a> to load .vue files. If you\u2019ve never heard of .vue files\u201a they basically take the idea of self contained components to the next level by allowing you to contain the template\u201a css and component logic within a single file\u201a and have it compile and render on your page at runtime. Nice right?<\/p>\n\n\n\nHowever\u201a the way the style loader works is that it inserts the css into the DOM in a style tag\u201a which could potentially pollute the styling of other elements on the page if your selectors are very generic. To get around this\u201a you can append the \u201cscoped\u201d attribute to the style tag. What this does is add a unique identifier to every element in your template\u201a and add this same rule to your styling rules so that that rule will only ever be applicable within the component that defined it. Great! No more leaky styles!<\/p>\n\n\n\n
However\u201a it\u2019s quite common (for me at least) to be using sub components within my single component\u201a for instance might pull in a component wrapper that has the HTML markup of a modal. So what if we want to tweak the styles in this instance of the wrapper component? As this component isn’t in the compilation scope our unique identifier won’t be applied to these elements.<\/p>\n\n\n\n
Luckily there is a solution to this. It\u2019s actually possible to use as many <\/p>\n","protected":false},"excerpt":{"rendered":"
When working with Vue\u201a the ideal development setup is to use vue-loader to load .vue files. If you\u2019ve never heard of .vue files\u201a they basically take the idea of self contained components to the next level by allowing you to contain the template\u201a css and component logic within a single file\u201a and have it compile and render […]<\/p>\n","protected":false},"author":2,"featured_media":2479,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","inline_featured_image":false,"footnotes":""},"categories":[151],"tags":[149,160],"acf":[],"yoast_head":"\n
Scoped vs Unscoped Styles in Vue Components | hedgehog lab<\/title>\n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n \n \n \n\t \n\t \n\t \n