Home > Net >  vue does not display .svg file in local env
vue does not display .svg file in local env

Time:12-07

I am making some project with Laravel, Vue2 now.
I deployed my project onto the test server, there .svg files display, but in my local environment they don't display.
I use :src="asset('images/ico_arrow_left1.svg')" in vue component. My images and svg files are all in root/public/images folder.

For example; I wrote the following code to display svg in vue component.

<a @click="previousDay"><img class="ico_ico_arrow" :src="asset('images/ico_arrow_left1.svg')"></a>

The codes are sampe in test server and local. show in test server, but not show in local, why?

CodePudding user response:

If you want import a file from public folder you should check the documentation. You should use require when you import dynamic asset. Like this:

<img class="ico_ico_arrow" :src="require('images/ico_arrow_left1.svg')"/>

CodePudding user response:

The asset() helper function is only for the Laravel Blade template. you can't use it inside of a regular Vue application.

In Vue, you should use require()in order to solve this problem.

  • Related