Vue public folder images in sass

Viewed 270

In my Vue-CLI project, all images are located inside public/media folder.

In Vue files, I was able to refer to public folder images with path /media/image.png

When I am trying to set a background in my sass

background-image: url('/media/image.png');

It throws the error below:

Module not found: Error: Can't resolve '/media/image.png' in 'myPath/src'

Look like by default sass is looking for images inside /src folder.

Is there a way to use images from /public folder?

1 Answers

Try using

background-image: url('~@/media/image.png');

Key here is using ~@ as a prefix. URLs prefixed with ~ are treated as a module request.

Related