需求是后端传入一个富文本,需要拿到富文本里面的第一张图片展示
getImgUrl(content) {
let matchReg = /<img.*?(?:>|\/>)/gi;
let arr2 = content.match(matchReg);
let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i;
let imgUrl = "";
if (arr2 != null) {
let src = arr2[0].match(srcReg);
imgUrl = src[1];
}
return imgUrl;
},
修改富文本的样式
通过deep来修改富文本里面可能会出现的标签的样式
<div class="my-style" v-html="item.content"></div>
.my-style {
font-size: 10px;
/deep/ p {
font-size: 10px;
}
/deep/ span {
font-size: 10px !important;
}
/deep/ strong {
font-size: 10px;
font-weight: inherit;
}
/deep/ video {
display: none;
}
}