|
@@ -173,12 +173,29 @@ export default {
|
|
|
this.isAdopt = true
|
|
|
}
|
|
|
})
|
|
|
- this.form = res.data
|
|
|
+ let form = res.data
|
|
|
+ form.text = this.imgReplace(form.text)
|
|
|
+ console.log('form',form)
|
|
|
+ this.form = form
|
|
|
+ // this.form = res.data
|
|
|
this.getUserInfoByUserId(this.form.createBy);//获取用户信息
|
|
|
this.selectCollect(id);//是否收藏
|
|
|
})
|
|
|
},
|
|
|
-
|
|
|
+ imgReplace (htmldoc) {
|
|
|
+ // 正则匹配所有img标签
|
|
|
+ // var regex0 = new RegExp("(i?)(\<img)([^\>]+\>)","gmi");
|
|
|
+
|
|
|
+ // 正则匹配不含style="" 或 style='' 的img标签
|
|
|
+ var reg1 = new RegExp("(i?)(\<img)(?!(.*?style=['\"](.*)['\"])[^\>]+\>)", 'gmi')
|
|
|
+ // 给不含style="" 或 style='' 的img标签加上style=""
|
|
|
+ htmldoc = htmldoc.replace(reg1, '$2 style=""$3')
|
|
|
+ // 正则匹配含有style的img标签
|
|
|
+ var reg2 = new RegExp("(i?)(\<img.*?style=['\"])([^\>]+\>)", 'gmi')
|
|
|
+ // 在img标签的style里面增加css样式(这里增加的样式:display:block;max-width:100%;height:auto;border:5px solid red;)
|
|
|
+ htmldoc = htmldoc.replace(reg2, '$2width:100%;$3')
|
|
|
+ return htmldoc
|
|
|
+ },
|
|
|
//获取用户信息:用户名称:头像
|
|
|
getUserInfoByUserId(userId) {
|
|
|
getUserInfo(userId).then((res) => {
|
|
@@ -244,6 +261,9 @@ export default {
|
|
|
.rich-text {
|
|
|
overflow: hidden;
|
|
|
}
|
|
|
+.rich-text p >img{
|
|
|
+ width: 100%;
|
|
|
+}
|
|
|
.effectBix {
|
|
|
width: 56px;
|
|
|
height: 56px;
|