Ionic image loading tips
P粉416996828
2023-08-26 20:03:50
<p>I'm just playing around with Ionic and Vue 3. </p>
<p>But when I use the <code>ion-img</code> tag, the images loaded from the assets folder are not displayed correctly. </p>
<p>Folder structure: </p>
<pre class="brush:php;toolbar:false;">- assets
-- logo.svg
- views
-- Authentication.vue</pre>
<p>When I load the image using standard HTML <code>img</code> it works fine, but not when using <code>ion-img</code>. </p>
<pre class="brush:php;toolbar:false;"><ion-row>
<img src="../assets/logo.svg"/>
<ion-img src="../assets/logo.svg"></ion-img>
</ion-row></pre>
<p>I have tried the following different src paths: </p>
<pre class="brush:php;toolbar:false;">./assets/logo.svg
../assets/logo.svg
../../assets/logo.svg (unreasonable, but I tried it too)
~/assets/logo.svg</pre>
<p>Any suggestions on this? </p>
Check out this answer:
How to reference static resources in vue javascript
In short, you can get the results you want by: