vue2.0 通过v-html指令编辑的富文本无法修改样式的原因
时间:2017-12-09 17:56:30
收藏:0
阅读:4181
在最近的项目中遇到的问题:v-html编辑的富文本,无法在样式表中修改样式;
<template> <div class="descBox" v-html=‘desc‘></div> </template> <script> export default{ data(){ return { desc: "<p>I believe I can fly</p>" } } } </script> <style> .descBox p{ color: blue; } </style>
比如上面的代码,生成的页面中,.descBox里面的P标签的样式并不是"color: blue";
这是为什么呢?原因很简单:如果标签存在template中,那么在<style></style>标签中是可以修改其样式的;
这应该是vue编译的规范吧,不存在的元素无法设置其样式;
解决方案:在updated生命周期函数中,js动态配置样式,代码如下
updated() { $(‘.descBox‘).find(‘p‘).css(‘color‘, ‘blue‘); },
ok,就这样完美解决;
原文:http://www.cnblogs.com/minigrasshopper/p/8011900.html
评论(0)