vue转义字符转换成普通字符

<script>
export default {
  name: "Myzufanghetong",
  data() {
    return {
      hetong:""
    }
  },
  methods: {
    back() {
      this.$router.go(-1);
    },
    escape2Html(str) {                            //转义字符转换普通字符的方法
      var arrEntities={'lt':'<','gt':'>','nbsp':' ','amp':'&','quot':'"'};
    return str.replace(/&(lt|gt|nbsp|amp|quot);/ig,function(all,t){return arrEntities[t];});
}
  },
  created(){
    this.util
          .request({
            url: "wmall/clientapi/mymixed",
            data: {
              ta: "renting_deal_new",
              id:this.$route.query.id
            },
          })
          .then((res) => {
            this.hetong = this.escape2Html(res.data.message.message.text)            //调用转义字符的方法
            // this.hetong = res.data.message.message.text.toString()
            console.log( this.hetong)
          });
  },
  // mounted(){
  //   this.$refs.mack.innerHTML = this.hetong
  // }
  
};
原文地址:https://www.cnblogs.com/ilylmy/p/13587048.html