3

I'm using the vue-markdown package to render markdown. It seems to work except the images don't display. The file path is correct as I can have an img show up correctly

<img src="@/assets/7801_4_lang_image.png"><!-- shows up -->
<vue-markdown>![img](@/assets/7801_4_lang_image.PNG)</vue-markdown><!-- doesn't show up -->

Changing the @ to .. doesn't change anything either, the top one displays but the bottom one doesn't. The case of png/PNG also doesn't matter. Am I referencing the image wrong?

1 Answer 1

3

The file loader doesn't know about images in Markdown so Webpack doesn't know to bundle them.

Typically you need to require() the image source (see https://cli.vuejs.org/guide/html-and-static-assets.html#relative-path-imports)

You could try this but I'm not entirely sure if it will work with the vue-markdown component.

![img]({{ require('@/assets/7801_4_lang_image.PNG') }})

To use the source prop, you would use something like

<vue-markdown :source="`![img](${require('@/assets/7801_4_lang_image.PNG')})`">

See https://v2.vuejs.org/v2/guide/syntax.html#Attributes


You could also use the public folder who's contents are always bundled. For example, for a file public/images/7801_4_lang_image.PNG and assuming your app runs at the domain root

![img](/images/7801_4_lang_image.PNG)
Sign up to request clarification or add additional context in comments.

1 Comment

the first option works if I put that between the tags <vue-markdown> but if it comes as a string and is loaded through :source the {} get encoded to %7B%7D and the image doesn't load again. Do you have any other ideas?

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.