M
M
Michael2017-08-09 18:00:13
Vue.js
Michael, 2017-08-09 18:00:13

How to write custom filters in vue js?

Interested in how to write your own filter in vue. I found on the net where native view filters are shown, and those who themselves wrote for some reason do not work.
For example, a simple word replacement function.
I did it in two ways but gives an error that they are doing it wrong.

filter: {
     vend: function(item){
         return item.replace("17", "RTX3");
      }
},

and
Vue.filter('vend',function(item){
     return item.replace("17", "RTX3");
 })

in template
<tr v-for="item in selected">
     <td>${item.vendor | vend }</td>
</tr>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Shashenkov, 2017-08-09
@DJWOMS1

Everything works
Updated for ${}

A
Anton Anton, 2017-08-09
@Fragster

it seems, everything works, only you need to use {{}} https://jsfiddle.net/pwrzkg1o/1/
Well, in general, the value of filters in this context is doubtful, I would use calculated properties.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question