I
I
Igor Bezlepkin2018-06-06 09:16:58
Vue.js
Igor Bezlepkin, 2018-06-06 09:16:58

How to call a function in a template in a template in Vue?

Hey! I do autocomplete. I want to find occurrences in the list of results and select them.

<li v-for="(item, key) in typeahead.items" :class="'typeahead-list__item ' + activeClass(key)" @mousemove="setActive(key)" @mousedown="hit" v-bind:key="key" v-bind:data-val="item.id">
  <div class="typeahead_body">{{ replace(item.city) }}</div>
</li>

replace: function (str) {
  return '<strong>Строка</strong>'
}

But it is displayed along with tags. Type as encodes tags in a line.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Kulakov, 2018-06-06
@kulakoff Vue.js

Just insert the strong tag directly into the template.

K
Konstantin Malyarov, 2018-06-06
@Konstantin18ko

*.html

<li v-for="(item, key) in typeahead.items" :class="'typeahead-list__item ' + activeClass(key)" @mousemove="setActive(key)" @mousedown="hit" v-bind:key="key" v-bind:data-val="item.id">
  <div class="typeahead_body">{{ item.city | replace }}</div>
</li>

Vue.filter('replace', function (value) {
  // value - это item.city
  return '<strong>' + value + '</strong>'
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question