在js里更改全局变量时加入换行符,但在div里引用渲染失效。
</-- 在div里引用全局变量text -->
<div>
{{this.text}}
</div>data() {return {// 全局变量初始值中有换行符text: '1\n给我换行!!!',}
}methods: {// 更改text值redactText(number,text) {this.text = number + '\n' + text; // 号码+换行+内容}
}
结果换行符变成了空格
解决方法:给div加上样式 white-space:pre-line;
<div style:"white-space:pre-line"style">
{{this.text}}
</div>
搞定!