在vue中后台返回的文本包含标签时候解析为html代码

1.对于后台返回的数据中含有html标签需要解析成html格式

数据格式:

str = "<p>亲爱的250。</p><p>你好。</p><p><br/></p>"  

在html中解析:

<p v-html="str">{{str}}</p>

 2.使用pre标签

<pre>{{str}}<pre>

样式white-space: pre-line 加上才会换行

.weekyContent pre{
  font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "5FAE8F6F96C59ED1", Arial, sans-serif;
  line-height: 28px;
  font-size: 16px;
  white-space: pre-line;
  margin: 0;
}

  

原文地址:https://www.cnblogs.com/wgl0126/p/11114063.html