HTML 识别 string 里的 '\n' 并成功换行?

102 阅读1分钟

原因: html 识别不了 '\n',所以不起换行的效果

Data:

this.tableData:[
     { "description": "指定支付方式。\n格式为数组字符串:\n  no_credit:指定不能使用信用卡支付。\n  no_balance:指定不能使用零钱支付。\n  no_debit:指定不能使用储蓄卡支付。\n  balance_only:指定只能使用零钱支付。", "fieldName": "limit_pay", "fieldType": "String", "require": true, "requireYesOrNo": "Y" },]

效果 :

识别不了'\n'

Snipaste_2024-01-17_14-49-52.png

参考方案:

在结果所在的 div 的 css 设置:


/** white-space: pre-line; **/

.doc_table {
	        white-space: pre-line;
		width: 100%;
		margin-top: 10px;
		border: 2px solid #cbe7fd;
		}

最后效果:

7281368eaa7b1cbd34e65a48a47fb8c.png