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

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

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

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/13332164.html