栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > Vue.js

VUE使用v-html获取文档后css样式不生效

Vue.js 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

VUE使用v-html获取文档后css样式不生效

官方关于v-html的解释如下:

在单文件组件里,scoped 的样式不会应用在 v-html 内部,因为那部分 HTML 没有被 Vue 的模板编译器处理。

解决方法:

1、去掉中的scoped,(不建议使用,会改变布局,导致组件之间样式冲突)


.content img{width:100%;height:auto;margin:.5rem auto;}
.content .contentimg{width:100%;height:auto;margin:.5rem auto;}

2、通过 >>> 可以使得在使用scoped属性的情况下,穿透scoped,修改其他组件的值


.content >>> img{width:100%;height:auto;margin:.5rem auto;}
.content >>> .contentimg{width:100%;height:auto;margin:.5rem auto;}

3、如果vue项目使用less或者sass的时候,>>>可能会失效,可以使用/deep/来代替


.content /deep/ img{width:100%;height:auto;margin:.5rem auto;}
.content /deep/ .contentimg{width:100%;height:auto;margin:.5rem auto;}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/239827.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号