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

时间:2020-07-17 19:33:34   收藏:0   阅读:243

新建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>
 
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!