Reputation: 956
Having my first go with VueJS which is great. Just got a couple of issues with data binding.
I need to build a URL with a static URL (amazon.com) with the binded image appended to the url. I have tried v-bind:href with no joy
<div class="main" id="vue-instance">
<!-- this will be the DOM element we will mount our VueJs instance to -->
Enter an image url:
<input type="text" v-model="myimage">
<img class="insert" style="max-height:300px" v-bind:src="myimage">
<a href="https://amazon.com" target="_blank">Link to the image</a>
</div>
Here is the code at JSFiddle
Upvotes: 0
Views: 1197
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
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