[英]Vue - how can i load CSS and JS files in a component?
我對 Vue 很陌生,我創建了一個要加載的導航欄組件。
這是我的代碼:
組件.vue
<template>
<html>
<head>
...
<link href="https://fonts.googleapis.com/css?family=Gudea:400,700" rel="stylesheet">
<link href="assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<!-- Theme Styles -->
<link href="assets/css/flatifytheme.min.css" rel="stylesheet">
<link href="assets/css/custom.css" rel="stylesheet">
...
</head>
<body>
...
<script src="assets/plugins/jquery/jquery-3.1.0.min.js"></script>
<script src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/plugins/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<script src="assets/plugins/waves/waves.min.js"></script>
<script src="assets/plugins/uniform/js/jquery.uniform.standalone.js"></script>
<script src="assets/plugins/switchery/switchery.min.js"></script>
<script src="assets/plugins/pace/pace.min.js"></script>
<script src="assets/js/flatifytheme.min.js"></script>
</body>
</html>
</template>
assets
目錄與組件位於同一文件夾中。
現在的問題是我有很多<link href=''>
和<scripts>
標簽加載我用於導航欄的主題的 js 和 css 文件,我不知道將它們放在哪里組件,所以我不斷收到以下錯誤:
This relative module was not found:
* ./components/testComponent in ./src/main.js, ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=script&lang=js&
這個錯誤是什么意思? 我該如何解決?
有兩種方法可以做到這一點:
main.js
或App.vue
中的捆綁程序加載項目文件import '@/assets/plugins/bootstrap/css/bootstrap.min.css'
等等...import '@/path/to/js/file'
加載項目文件:<style>
@import '@/path/to/js/file';
</style>
在樣式標簽中使用 @import 來導入 CSS 文件。
@import './assets/plugins/font-awesome/css/font-awesome.min.css'
文件的路徑也不正確,請使用./
。
./assets/plugins/jquery/jquery-3.1.0.min.js
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.