search

Home  >  Q&A  >  body text

html5 - How to perform expression judgment on escape characters in vue.js?

<text class="iconfont">{{selected == item.id ? '' : ''}}</text>
Write it like this, I Able to display the correct iconfont
However,
<text class="iconfont">{{selected == item.id ? item.selIcon : item.nmlIcon}}</text>
Define
nmlIcon in data: '',
selIcon : ''
At this time, I can’t display it

What is the reason for this? Experts, please give me some analysis, thank you!

漂亮男人漂亮男人2814 days ago788

reply all(1)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-24 11:38:59

    This is because when you put a string in HTML, it is first parsed by Vue and then obtained by the browser, so the result is already escaped when it reaches Vue.

    {{}}v-text 是设置元素的 textContent, so it will not be escaped.

    So you can use {{{}}} 或者 v-html instead.

    reply
    0
  • Cancelreply