2 次代碼提交 cd0e5d00ae ... 0992fc4a9b

作者 SHA1 備註 提交日期
  yuhang Fu 0992fc4a9b Merge branch 'master' of http://192.168.10.18:3000/sooka_shop/sooka_consult_uniapp 1 年之前
  yuhang Fu a57eca045a 问吧详情 图片修改 1 年之前
共有 1 個文件被更改,包括 22 次插入2 次删除
  1. 22 2
      pages/asking/questiondetails.vue

+ 22 - 2
pages/asking/questiondetails.vue

@@ -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;