久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

背景圖像未在電子應用程序中加載

Background image not loading in Electron Application(背景圖像未在電子應用程序中加載)
本文介紹了背景圖像未在電子應用程序中加載的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在 login.vue 組件所在的目錄中有一個圖像文件(以下代碼所在的位置).但是,當我嘗試此代碼時,圖像將無法加載:

I have an image file in the same directory as my login.vue component (which is where the following code is located). But, when I try this code, the image will not load:

<div background="benjamin-child-17946.jpg" class="login" style="height:100%;">

我收到此錯誤:

加載資源失敗:服務器響應狀態為 404(未找到)

Failed to load resource: the server responded with a status of 404 (Not Found)

這很奇怪,因為我可以在終端中看到我的圖像與 login.vue 位于同一目錄中.我正在使用 webpack 進行編譯.這可能是什么原因造成的?

This is strange, because I can see in my terminal that my image is in the same directory as login.vue. I am using webpack to compile. What might be causing this?

推薦答案

您的主要問題是編譯單個文件組件并且編譯后的腳本不太可能與您的圖像位于當前位置的同一目錄中.您的第二個問題是您沒有正確地將背景圖像分配給 div.你應該使用 CSS.

Your primary issue is that single file components are compiled and the compiled script is very unlikely to reside in the same directory as the current location as your image. Your second issue is that you are not assigning the background image to your div correctly. You should use CSS.

我建議您在電子應用程序(或資產或靜態或任何您想調用的名稱)的根目錄中創建一個 images 目錄.然后,您可以使用 file:// 協議引用該目錄中的文件.

I would suggest that you make an images directory in the root of your electron application (or assets or static or whatever you want to call it). Then, you can reference files in that directory using the file:// protocol.

其次,我建議您定義一個 CSS 類并使用它.因此,在您的單個文件組件中,定義此樣式部分:

Second, I would recommend you define a CSS class and use that. So, in your single file component, define this style section:

<style>
  .background {
    background: url('file:///images/benjamin-child-17946.jpg') no-repeat center center fixed; 
    background-size: cover
  }
</style>

在你的 div 上使用類.

And on your div just use the class.

<div class="login background">

最后,您還可以使用 webpack 的 url-loader 將文件加載為 dataUrl 但我建議作為更高級的練習并堅持簡單暫時.

Finally, you could also use webpack's url-loader to load the file as a dataUrl but I would recommend that as a more advance exercise and just stick with the simple for now.

編輯

我使用 electron-vue 從頭開始??創建了一個項目,它使用了 webpack,我確實遇到了上面使用 file:// 協議的錯誤,我在不使用 webpack 時不會遇到.使用上面的模板,而不是使用file:///images/benjamin-child-17946.jpg,把文件放到static目錄下,使用/static/benjamin-child-17946.jpg.這允許 vue-loader 正常工作.

I created a project from scratch using electron-vue which uses webpack and I did run into an error with the above using the file:// protocol, that I don't run into when not using webpack. With the above template, instead of using file:///images/benjamin-child-17946.jpg, put the file in the static directory and use /static/benjamin-child-17946.jpg. That allows vue-loader to work properly.

如果你沒有使用 electron-vue,那么你的 webpack 配置可能會有所不同.

If you are not using electron-vue, then your webpack configuration may be different.

這篇關于背景圖像未在電子應用程序中加載的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to getCurrentPosition via navigator.geolocation in Electron app?(如何通過電子應用程序中的 navigator.geolocation 獲取當前位置?)
Receipt thermal printer in Electron(Electron 收據熱敏打印機)
how to fix blank page if i am using vue router with electron js?(如果我使用帶有電子 js 的 vue 路由器,如何修復空白頁?)
electron, after browserify, fs.existsSync is not a function(electron,browserify之后,fs.existsSync不是函數)
Easy way to load local html file in electron(在電子中加載本地 html 文件的簡單方法)
How to manage configuration for Webpack/Electron app?(如何管理 Webpack/Electron 應用程序的配置?)
主站蜘蛛池模板: 亚洲一区 | 一本一道久久a久久精品综合蜜臀 | 亚洲一区亚洲二区 | 亚洲视频免费一区 | 国产欧美一区二区三区日本久久久 | 中文字幕一区二区三区精彩视频 | 久草在线| 一呦二呦三呦国产精品 | 精品久久久久久亚洲精品 | 女人牲交视频一级毛片 | 99精品国产成人一区二区 | 日本黄色激情视频 | 性欧美xxxx| 午夜在线小视频 | 亚洲成人福利视频 | 国产精品久久久久一区二区三区 | 国产精品婷婷 | 亚洲第一在线视频 | 久久伊人影院 | 美国av毛片 | 农村黄性色生活片 | 久久一区二区视频 | jizz视频| 伊人焦久影院 | 一级欧美一级日韩片 | 久久久久久成人 | 亚洲欧美在线观看 | 中文字幕一区二区三区在线视频 | 狠狠操狠狠搞 | 日韩av在线中文字幕 | 午夜视频一区二区 | www.五月婷婷.com| 日韩毛片视频 | 亚洲欧美日韩高清 | 欧美精品一区二区三区在线播放 | 成年人在线观看 | 精品国产免费一区二区三区演员表 | 久久久久久99 | 一区二区视频 | 日本久久网站 | 狠狠干网站 |