Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0.2新版本taro text标签 decode换行处理失效 #7003

Closed
dreamthen opened this issue Jul 11, 2020 · 6 comments
Closed

3.0.2新版本taro text标签 decode换行处理失效 #7003

dreamthen opened this issue Jul 11, 2020 · 6 comments
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@dreamthen
Copy link

相关平台

微信小程序

复现仓库

https://github.com/dreamthen/PetPlanet-demo
小程序基础库: 2.11.3
使用框架: React

复现步骤

拉取代码,直接使用111111\n,就可以看到,decode对于换行符不起作用

期望结果

taro text标签 decode换行处理生效

实际结果

taro text标签 decode换行处理失效

环境信息

👽 Taro v3.0.2


  Taro CLI 3.0.2 environment info:
    System:
      OS: macOS 10.15.5
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 12.18.0 - /usr/local/bin/node
      Yarn: 1.22.4 - /usr/local/bin/yarn
      npm: 6.14.6 - /usr/local/bin/npm
    npmPackages:
      @tarojs/components: 3.0.2 => 3.0.2 
      @tarojs/mini-runner: 3.0.2 => 3.0.2 
      @tarojs/react: 3.0.2 => 3.0.2 
      @tarojs/runtime: 3.0.2 => 3.0.2 
      @tarojs/taro: 3.0.2 => 3.0.2 
      @tarojs/webpack-runner: 3.0.2 => 3.0.2 
      babel-preset-taro: 3.0.2 => 3.0.2 
      eslint-config-taro: 3.0.2 => 3.0.2 
      nerv-devtools: 1.5.7 => 1.5.7 
      nervjs: 1.5.7 => 1.5.7 
      react: ^16.10.0 => 16.13.1 
    npmGlobalPackages:
      typescript: 2.8.3

@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Jul 11, 2020
@dreamthen
Copy link
Author

dreamthen commented Jul 11, 2020

@Chen-jj @luckyadam

@dreamthen
Copy link
Author

感觉这个问题很严重呀,Text标签不能处理换行符,这是比较基础的问题呀

@Chen-jj
Copy link
Contributor

Chen-jj commented Jul 16, 2020

@dreamthen \n 应该被 react 转了为 \\n,这样写吧:

<Text decode dangerouslySetInnerHTML={{ __html: '1111\n'}}  />

@Chen-jj Chen-jj closed this as completed Jul 16, 2020
@dreamthen
Copy link
Author

好的,我试一下

@qingsikou
Copy link

@dreamthen \n 应该被 react 转了为 \\n,这样写吧:

<Text decode dangerouslySetInnerHTML={{ __html: '1111\n'}}  />

还是无效

@toFrankie
Copy link
Contributor

toFrankie commented May 23, 2022

@dreamthen \n 应该被 react 转了为 \\n,这样写吧:

<Text decode dangerouslySetInnerHTML={{ __html: '1111\n'}}  />

还是无效

  1. 对需要渲染的字符串处理:str.replace(/\\n/g, '\n')
  2. 其次需要设置 white-space: pre-wrap

写原生小程序,也会将 \n 转为 \\n 的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

4 participants