One major issue you are facing is that single file components get compiled and the resulting script may not be in the same location as your image. Additionally, there seems to be a problem with how you are assigning the background image to your div
. Utilizing CSS would be more appropriate for this task.
A potential solution could involve creating an images
directory at the root of your electron application (or any desired name like assets or static). This way, you can reference files within that directory using the file://
protocol.
Furthermore, it is recommended to define a CSS class and apply it to your element. Within your single file component, include a style section like:
<style>
.background {
background: url('file:///images/benjamin-child-17946.jpg') no-repeat center center fixed;
background-size: cover
}
</style>
Then, simply add the defined class to your div element.
<div class="login background">
If needed, you could explore using webpack's url-loader
to load the file as a dataUrl
, but starting with the simpler approach is recommended.
Edit
In a test project created with electron-vue (which utilizes webpack), I encountered an error when using the file://
protocol mentioned above. To avoid this issue, place the image in the static
directory and change the path to /static/benjamin-child-17946.jpg
. This adjustment enables vue-loader
to function correctly.
Note that if you are not using electron-vue
, your webpack configuration may vary.