Concatenate string with Vue in href

0

I need to play this URL within href:

http://localhost:62828/colecoes/channel.aspx?channelId=30271973&category=4

However, instead of channelId = 30271973 I need to concatenate with {{collection.Id}}

Below my href:

<h3 class="item-title"><a href="">{{colecao.tituloCanal}}</a></h3>
    
asked by anonymous 23.02.2018 / 04:13

2 answers

1

You can do this:

<h3 class="item-title"><a :href="'http://localhost:62828/colecoes/channel.aspx?channelId=' + colecao.Id + '&category=4'">{{colecao.tituloCanal}}</a></h3>

Or

<h3 class="item-title"><a v-bind:href="'http://localhost:62828/colecoes/channel.aspx?channelId=' + colecao.Id + '&category=4'">{{colecao.tituloCanal}}</a></h3>
    
23.02.2018 / 04:25
3

You can use a reactive value ( computed ) for this, if you do the concatenation in the template it was not able to cache and will calculate every render .

It would look like this:

Template:

<h3 class="item-title"><a :href="url">{{colecao.tituloCanal}}</a></h3>

Component:

computed: {
    url(){
        return 'http://localhost:62828/colecoes/channel.aspx?channelId=${this.colecao.Id}&category=4';
    }
}
    
23.02.2018 / 07:18