Gracie
Gracie

Reputation: 956

Data binding in VueJS to build a URL

Having my first go with VueJS which is great. Just got a couple of issues with data binding.

Here is the code at JSFiddle

Upvotes: 0

Views: 1197

Answers (2)

Prabhat Thapa
Prabhat Thapa

Reputation: 45

You can set myimage='' or null initially. Then You can use v-if statement to only show the image and image link if there is some value in myimage

<div v-if="myimage">
    <img class="insert" style="max-height:300px" v-bind:src="myimage">
    <a v-bind:href="'https://amazon.com/' + myimage" target="_blank">Link to the image</a>
</div>

Upvotes: 1

Josh
Josh

Reputation: 956

You can use v-bind:href and then normal javascript inside the property like below

<a v-bind:href="'https://amazon.com/' + myimage" target="_blank">Link to the image</a>

note the additional '' in the v-bind property

As for not displaying the image until after a url is entered, you can use a simple v-show

<img class="insert" style="max-height:300px" v-show="myimage != null" v-bind:src="myimage">

This will hide the image when myimage is null

Upvotes: 0

Related Questions