2

I'm trying to do the following, but the image doesn't output correctly. Where I display the image in display.vue, if I print {{ someText }}, I get the correct file path (../assets/city.png).

display.vue

<template>
    <example :someText="'../assets/' + stamp + '.png'"></example>
</template>

<script>
import example from './example.vue'

export default {
    name: "",
    data() {
        return {
            stamp: "city"
        }
    }
    components: [
        example
    ]
};
</script>

example.vue

<template>
    <img :src="someText" />
</template>

<script>
    export default {
      name: "example",
      props: ["someText"]
    };
</script>
3
  • What do you mean by "doesn't output correctly"? Is the image showing at all? Commented Aug 31, 2018 at 21:16
  • @Stephen Thomas It shows the default image symbol. Commented Aug 31, 2018 at 21:25
  • Have you verified that the file exists in the specified location? rememet that relative urls (like the one you use) are relative to the current url location of the browser Commented Aug 31, 2018 at 23:15

2 Answers 2

3

You need to change your props case format:

HTML attribute names are case-insensitive, so browsers will interpret any uppercase characters as lowercase. That means when you’re using in-DOM templates, camelCased prop names need to use their kebab-cased (hyphen-delimited) equivalents (source)

It should work this way:

<template>
  <example :some-text="'../assets/' + stamp + '.png'"></example>
</template>
Sign up to request clarification or add additional context in comments.

1 Comment

OP isn't using in-DOM templates, so camelCase isn't the issue here.
0

This kind of thing happened to me also. In your example.vue try this

<template>
    <img src="../assets/city.png" />
</template>

If this not gives you the correct output. Then try with the full path

<template>
    <img src="src/assets/city.png" />
</template>

My case was image doesn't read from ../assets/city.png but it reads from src/assets/city.png

3 Comments

Maybe I don't know. What I said is what worked for me. =)
Ok)). In my project work code <img src="@/assets/logo.png" />
I think different web pack versions has to have different syntax. Anyways we both can say changing the path as you mentioned or as I mentioned should solve this question. =)

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.