[Vuejs]-Syntax of Vue.js filter within v-bind:href

1πŸ‘

From what I get here is that you are trying to use a filter as method. You can achieve this using this.$options.filters.filterName().
For the given case, you should try something like:

<a v-bind:href="'https://mysite.mydatabase?ID='+$options.filters.shorten(longid )">{{ longid }}</a>.

Fiddle for reference: https://jsfiddle.net/sharitu/nbm2v1dx/3/

0πŸ‘

  1. You can define method shorten and use like

<a v-bind:href="`https://mysite.mydatabase?ID=${shorten(longid)}`">{{ longid }}</a>

  1. Consider change your shorten function:
shorten: function(myString){
   return myString.split('.').pop()
}

-1πŸ‘

Try this:

     <a v-bind:href="'https://mysite.mydatabase?ID='+longid | shorten(longid)">{{ longid }}</a>

Your filters function should change like this:

     filters: {
         shorten: function(myString,longid){
            //return your code;
         }
     },

First argument is the url and second argument is longid parameter

Leave a comment