0

My Vue project structure is:-

|-public
|   |-symbol
|       |-smally.JPG
|-src
|  |-components
|      |-Header.vue
|-App.vue

Header.vue contains :-

<template>
   <ons-page>
        <div class="toolbar">
            <div class="toolbar__left">
                 <img src="./public/symbol/{{HeaderImage}}"/>
            </div>
        </div>
    </ons-page>
</template>
<script type="text/javascript">
export default{
    name:'Header',
    props:['HeaderImage']
}
</script>

while App.vue contains,

<template id="main-page">
    <Header HeaderImage="smally.jpg"/>
</template>

<script>
  import Header from './components/Header.vue'

  export default {
     name: 'app',
     components: {
       Header
      }
  }
</script>

It's not working

2 Answers 2

1

You don't need to put ./public/

<img :src="'symbol/' + HeaderImage"/>
Sign up to request clarification or add additional context in comments.

3 Comments

Maybe because the filename is smally.JPG while the value of HeaderImage is smally.jpg.
It's not working because if :src bind if the whole value is variable. say if HeaderImage has symbol/smally.jpg but in my case it's not working
Check the updated code. I completely forgot about data binding.
0
  1. Create a new folder in src named with assets
  2. Put your image into assets folder
  3. Change <img src="./public/symbol/{{HeaderImage}}"/> to <img :src="'~/assets/' + HeaderImage"/> in your Header.vue file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.