新建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>