发布于 

v-html中\n换行

问题:直接使用v-html会发现\n不会换行
问题解决:加上style="white-space: pre-line"

示例

1
2
3
4
5
6
<template>  
<div style="white-space: pre-line" v-html="htmlStr"></div>
</template>
<script setup>
const htmlStr = ref('第一行\n\n'我是第二行)
</script>

效果:

1
2
第一行
我是第二行