2017-03-07 65 views
0

在我的項目試圖引用CSS時,我收到以下錯誤加載從bower_components資源和JS文件無法使用Vue.js CLI

Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:8080/bower_components/bootstrap/dist/css/bootstrap.min.css 

這是我的文件結構

app 
    |bower_components 
     |bootstrap 
      |dist 
       |css 
        | bootstrap.min.css 
     |jquery 
      |dist 
       |jquery.min.js 
    |build 
    |config 
    |node_modules 
    |src 
    |static 
    |index.html //The file I am receiving error on 
public //using Slim framework with PHP to generate RESTful API 
src 
vendor 

在我的index.html文件我正在使用以下代碼嘗試引用bootstrap.min.css文件

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <title>Template</title> 
    <link rel="stylesheet" href="./bower_components/bootstrap/dist/css/bootstrap.min.css"> 
    </head> 
    <body> 
    <div id="app"></div> 
    </body> 
</html> 

我正在使用Visual Studio代碼,這使得能夠CTRL +單擊鏈接到bootstrap.min.css文件並加載好,所以我不確定我在哪裏出錯了?

我使用vue.js CLI作爲app文件夾,並使用與Slim FrameworkPHP產生如果那幫助public/src/vendor文件夾一個RESTful API?任何幫助將不勝感激。

+0

你試過從鏈接「./」刪除? – Aaron

+0

@Aaron是的,仍然收到相同的錯誤。我已經嘗試過使用vue.js CLI,它的工作原理,所以它肯定與此有關,只是不知道如何... – mcclosa

回答

0

我能夠解決這個問題,它與使用Vue.js CLI鏈接。

我需要添加的文件夾bower_components爲靜態文件夾,然後引用該文件就像

<link rel="stylesheet" href="./static/bower_components/bootstrap/dist/css/bootstrap.min.css">