1.英文超长自动换行-单词不折断
<div v-text="content" class="wrap-con"></div>
.wrap-con {
display: inline-block;
width: 300px;
height: 150px;
overflow: auto;
border: 1px solid #efefef;
word-wrap: break-word; // 单词不折断换行
}

英文单词不折断换行
2.中文换行
<div v-text="content" class="wrap-con"></div>
mounted() {
// mock 数据
for(let i = 0; i < 100; i++) {
this.content = `${this.content}
三十功名尘与土 ${i}`;
}
}
.wrap-con {
display: inline-block;
width: 30%;
height: 150px;
overflow: auto;
border: 1px solid #efefef;
word-wrap: break-word; // 中文换行
white-space: pre; // 识别回车; 如果是 normal, 表示默认值, 回车会被浏览器忽略;
}

中文超长换行-识别回车

中文超长换行-回车被忽略
网友评论