Introduction to the method of adding scoped styles to the dom rendered by v-html in Vue.js

不言
Release: 2019-04-11 10:33:21
forward
2990 people have browsed it

This article brings you an introduction to the method of adding scoped styles to the dom rendered by v-html in Vue.js. It has certain reference value and friends in need can refer to it. I hope it helps you.

In vue.js, to render a string into html, you can use the v-html directive.

But the v-html part of the official documentation also reminds

that in a single file component, the scopedstyle will not be applied tov -htmlinternally, because that part of HTML is not processedby Vue's template compiler. If you wish to set scoped CSS for the content of v-html, you can replace it with CSS Modules or manually set a BEM-like scoping strategy with an additional global
The above code will be compiled into:
.a[data-v-f3f3eg9] .b { / .. ./ }
Some preprocessors like Sass cannot parse >>> correctly. In this case you can use the /deep/ operator instead - this is an alias for >>> and will work just as well.

Example

Copy after login

[Related recommendations:JavaScript video tutorial]

The above is the detailed content of Introduction to the method of adding scoped styles to the dom rendered by v-html in Vue.js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!