简体   繁体   English

Vue降价图像不显示

[英]Vue markdown Image not displaying

I'm using the vue-markdown package to render markdown.我正在使用vue-markdown包来渲染 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

<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. png/PNG 的大小写也无关紧要。 Am I referencing the image wrong?我是否引用了错误的图像?

The file loader doesn't know about images in Markdown so Webpack doesn't know to bundle them.文件加载器不知道 Markdown 中的图像,因此 Webpack 不知道捆绑它们。

Typically you need to require() the image source (see https://cli.vuejs.org/guide/html-and-static-assets.html#relative-path-imports )通常您需要require()图像源(请参阅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.你可以试试这个,但我不完全确定它是否适用于vue-markdown组件。

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

To use the source prop, you would use something like要使用source道具,您可以使用类似的东西

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

See https://v2.vuejs.org/v2/guide/syntax.html#Attributeshttps://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例如,对于文件public/images/7801_4_lang_image.PNG并假设您的应用程序在域根目录下运行

![img](/images/7801_4_lang_image.PNG)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM