text标签动态绑定文本,文本中\n换行不生效问题解决
发布于 3 年前 作者 tanggang 4003 次浏览 来自 分享
#原文链接:https://blog.csdn.net/weixin_40285832/article/details/90753467
#原文作者:weixin_40285832
#个人学习记录,新手新手新手,不严谨的地方还请指正,感谢感谢

1、新建filter.wxs文件

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

module.exports = {
    format:format
}

2、在需要使用的页面导入wxs模块:

<wxs src="../../common/filter.wxs" module="util"></wxs>

3、在需要转换的text中使用方式如下:

<text>{{util.format(text)}}</text>
回到顶部