微信小程序-服务器返回数据中包含有\n换行符失效问题解决方案

时间:2020-08-13 12:18:16   收藏:0   阅读:427

------------恢复内容开始------------

新建filter.wxs文件,文件内容如下

var format = function (text) {
if (!text) {
return
}
var reg = getRegExp(‘\\\\n‘, ‘g‘)
return text.replace(reg,‘\n‘)
}

module.exports = {
format:format
}
————————————————


在需要使用的wxml中导入wxs模块

<!--导入wxs模块,只能使用相对路径,并需要定义module-->
<wxs src="../filter.wxs" module="util"></wxs>

 

在text标签中使用时,需要使用util.format()的方法j将服务器返回的数据当做参数传到方法中就可以了

<text class="content">{{util.format(book.summary)}}</text>
 

------------恢复内容结束------------

原文:https://www.cnblogs.com/xzhce/p/13495005.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!