欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

uniapp開發(fā)支付寶小程序/微信小程序時(shí),顯示富文本文件 - 新聞資訊 - 云南小程序開發(fā)|云南軟件開發(fā)|云南網(wǎng)站建設(shè)-昆明葵宇信息科技有限公司

159-8711-8523

云南網(wǎng)建設(shè)/小程序開發(fā)/軟件開發(fā)

知識(shí)

不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們?cè)谧非笃湟曈X表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營(yíng)銷的便利,運(yùn)營(yíng)的高效,讓網(wǎng)站成為營(yíng)銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏?jí)提供便捷的支持!

您當(dāng)前位置>首頁(yè) » 新聞資訊 » 小程序相關(guān) >

uniapp開發(fā)支付寶小程序/微信小程序時(shí),顯示富文本文件

發(fā)表時(shí)間:2020-10-14

發(fā)布人:葵宇科技

瀏覽次數(shù):144

微信

<!-- #ifndef MP-ALIPAY -->
 	<view class="detailsContent"  v-html="imgStyle(details.text)">
  	 </view>
<!-- #endif -->
imgStyle(val){
	if(val!=''&&val!=undefined&&val!=null){
		return val?.replace(/<img/g, '<img style="max-width: 100%!important;display: block;margin: 0 auto;"')
	}else{
		return val;
	}
},

支付寶

 <!-- #ifdef MP-ALIPAY -->
	<rich-text :nodes="changeText(details.text)"></rich-text>
	<!-- #endif -->
/**支付寶處理富文本文件*/
	changeText(html){
		/**
		 * 處理富文本里的圖片寬度自適應(yīng)
		 * 1.去掉img標(biāo)簽里的style、width、height屬性
		 * 2.img標(biāo)簽添加style屬性:max-width:100%;height:auto
		 * 3.修改所有style里的width屬性為max-width:100%
		 * 4.去掉<br/>標(biāo)簽
		 * @param html
		 * @returns {void|string|*}
		 */
		if(html!=''&&html!=undefined&&html!=null){
		let newContent= html.replace(/<img[^>]*>/gi,function(match,capture){
			match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
			match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
			match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
			return match;
		});
		newContent = newContent.replace(/style="[^"]+"/gi,function(match,capture){
			match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
			return match;
		});
		newContent = newContent.replace(/<br[^>]*\/>/gi, '');
		newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"');
		//將 HTML String轉(zhuǎn)化為 nodes 數(shù)組
		const content = new HTMLParser(newContent.replace()?.trim());
		return content;
		}else{
			return html;
		}
	}

用到的類庫(kù) html-parser.js

相關(guān)案例查看更多