0

I want to pass a image path from a tag that built by Vue to vue component(MyPost):

<my-post txt="Such a great Framework, Rouzbeh Said!" url="image.png"></my-post> 

I use parameter in component like this but didn't work:

<img src="{{ url }}" alt="post-picture"> 

My component in Vue:

<script> Vue.component('MyPost',{ props: ['txt', 'url'], template: ` <div class="col"> <div class="card shadow-sm"> // this line didnt work <img src="{{ url }}" alt="post-picture"> <div class="card-body"> <p class="card-text">{{txt}}</p> <div class="d-flex justify-content-between align-items-center"> <div class="btn-group"> <button type="button" class="btn btn-sm btn-outline-secondary">View</button> <button type="button" class="btn btn-sm btn-outline-secondary">Edit</button> </div> <small class="text-muted">9 mins</small> </div> </div> </div> </div> ` }); var app = new Vue({ el: "#app", }); </script> 

1 Answer 1

1

You should use :src instead of src to indicate that you have an expression and not a static text:

<img :src="url" alt="post-picture"> 

{{ and }} should be used only in a tag content and not in tag attributes

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.