![](/img/trans.png)
[英]Vue.js / Webpack build “index.html” using a “static” subdomain for CSS and JS
[英]Vue.js css and js declared in index.html are not working
我下載了一個提供 html、css3、js 文件的主題,並添加了如下源代碼的路徑
<!-- Basic -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Porto - Responsive HTML5 Template 7.5.0</title>
<meta name="keywords" content="HTML5 Template" />
<meta name="description" content="Porto - Responsive HTML5 Template">
<meta name="author" content="okler.net">
<!-- Theme CSS -->
<link rel="stylesheet" href="/static/css/theme.css">
<link rel="stylesheet" href="/static/css/theme-elements.css">
<link rel="stylesheet" href="/static/css/theme-blog.css">
<link rel="stylesheet" href="/static/css/theme-shop.css">
<!-- Current Page CSS -->
<link rel="stylesheet" href="/static/vendor/rs-plugin/css/settings.css">
<link rel="stylesheet" href="/static/vendor/rs-plugin/css/layers.css">
<link rel="stylesheet" href="/static/vendor/rs-plugin/css/navigation.css">
<!-- Demo CSS -->
<!-- Skin CSS -->
<link rel="stylesheet" href="/static/css/skins/skin-corporate-5.css">
<!-- Theme Custom CSS -->
<link rel="stylesheet" href="/static/css/custom.css">
<!-- Head Libs -->
<script src="/static/vendor/modernizr/modernizr.min.js"></script>
當我剛開始接近時它運行良好但是,當我使用路由器移動時,它不會運行一些 css 和 JavaScript。
所以我試圖在組件文件上添加一個 javascript 路徑
<template>
<div role="main" class="main">
test
</div>
</template>
<script>
import "/static/js/theme.js"
</script>
當我這樣嘗試時,我可以看到此錯誤
This dependency was not found:
* /static/js/theme.js in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/parents/Robot.vue
To install it, you can run: npm install --save /static/js/theme.js
有沒有辦法再次加載整個 index.html? 或解決此問題的另一種方法?
不要在 index.html 文件路徑中寫入靜態,而是使用 <%= BASE_URL %>。 例如,不要使用href="/static/vendor/modernizr/modernizr.min.js"
添加所有 css 和腳本文件,而是這樣寫href="<%= BASE_URL %>/vendor/modernizr/modernizr.min.js"
嘗試直接在 App.vue 文件中的 main.js 和樣式表中添加腳本。 我在 index.html 文件中導入文件時遇到了很多問題。 但是當我移動所有進口時,一切正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.