2

here's one of my computed methods:

            filtered() {
                return this.groups.map(group => {
                    return group.replace(this.search, '<span class="has-background-primary">' + this.search + '</span>');
                })
            }

This is supposed to highlight text in a searchbox, but the < is escaped to &lt;. What should i do to suppress escaping or how can I do it better?

3
  • 1
    wha r u trying to do because as it looks from here you can do this with v-if Commented Oct 3, 2018 at 16:09
  • I'm trying to highlight searched text. if I have 'mozambik' in the list and 'zam' in searchbox i want to have moZAMbik, where caps letter are highlighted so it should look like: Mo<span class="has-background-primary">zam</span>bik Commented Oct 3, 2018 at 16:11
  • 1
    Might be similar to this. stackoverflow.com/questions/30877491/vue-display-unescaped-html Commented Oct 3, 2018 at 16:27

1 Answer 1

7

You're on the right track. The only thing missing is a v-html at the place where you render your result/list.

<div v-for="item in items" v-html="item">
  <!-- if the item now contains raw html it will not be escaped -->
</div>

I've created a small fiddle for demonstration: http://jsfiddle.net/6bto2nkv/

Sign up to request clarification or add additional context in comments.

2 Comments

that was it, I tried with triple braces, but I guess that was old syntax
Yes, in vue 2.0 the triple moustache has been deprecated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.