encodeURIComponent()加密、decodeURIComponent()解码及v-html将字符串转换为html

1)新闻详情页后台给我的数据是加密之后的,我问了后台,是用encodeURIComponent()加密的,然后我就用对应的方法decodeURIComponent()解密:

this.$store.state.news.main =decodeURIComponent(data.FormattedBody);

2)  然后{{this.$store.state.news.main}}这样填数据,等我看页面的时候,页面上出现了一串字符串,然后我就想起了v-html,   

<div v-html="this.$store.state.news.main">
  {{this.$store.state.news.main}}
</div>

注意:v-html的引号里面的内容要和{{}}的内容是一样的,这样,页面就正常显示了

原文地址:https://www.cnblogs.com/eyed/p/7867141.html