使用text标签时,\n可换行,但是如果内容是从网络中获取的,如何换行呢?
发布于 4 年前 作者 chenjing 7898 次浏览 来自 官方Issues

index.wxml

<text>{{content}}</text>

index.js

const app = getApp()

Page({
  data: {
    content'Hello World',
  },
  onLoadfunction(){
    var that = this;
    wx.request({
      url'https://test.uaivg.com/test',
      successfunction(res){
        console.log(res);
        that.setData({
          content: res.data
        });
      }
    });
  }
})

运行结果

1 回复

that.setData({

  content: res.data.replace(/\\n/g, '\n')

});

回到顶部