最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - VUE CLI - How to import scripts and styles - Stack Overflow

programmeradmin1浏览0评论

Please I have been trying to import local styles and javascript files into my newly created VUE-CLI 3 application (inside public/index.hml) but they are not reflecting in my components.

Using Vue-cli 2 it works.

Are we not supposed to import css and styles in public/index.hml Please how do i get this to work? Please help.

See below how i referenced the files in public/index.html file

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>vue-cameleon</title>

    <link href="+Sans:300,400,700" rel="stylesheet">

    <!-- Common CSS -->
    <link rel="stylesheet" href="../src/assets/css/bootstrap.min.css" />
    <link rel="stylesheet" href="../src/assets/fonts/icomoon/icomoon.css" />
    <link rel="stylesheet" href="../src/assets/css/main.css" />

    <!-- Other CSS includes plugins - Cleanedup unnecessary CSS -->
    <!-- Chartist css -->
    <link href="../src/assets/vendor/chartist/css/chartist.min.css" rel="stylesheet" />
    <link href="../src/assets/vendor/chartist/css/chartist-custom.css" rel="stylesheet" />

Please I have been trying to import local styles and javascript files into my newly created VUE-CLI 3 application (inside public/index.hml) but they are not reflecting in my components.

Using Vue-cli 2 it works.

Are we not supposed to import css and styles in public/index.hml Please how do i get this to work? Please help.

See below how i referenced the files in public/index.html file

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>vue-cameleon</title>

    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,700" rel="stylesheet">

    <!-- Common CSS -->
    <link rel="stylesheet" href="../src/assets/css/bootstrap.min.css" />
    <link rel="stylesheet" href="../src/assets/fonts/icomoon/icomoon.css" />
    <link rel="stylesheet" href="../src/assets/css/main.css" />

    <!-- Other CSS includes plugins - Cleanedup unnecessary CSS -->
    <!-- Chartist css -->
    <link href="../src/assets/vendor/chartist/css/chartist.min.css" rel="stylesheet" />
    <link href="../src/assets/vendor/chartist/css/chartist-custom.css" rel="stylesheet" />

Share Improve this question edited Jun 9, 2020 at 15:02 Boussadjra Brahim 1 asked Oct 5, 2018 at 18:17 golf4spgolf4sp 1291 gold badge1 silver badge4 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 14

You could import them in the main.js as follows :

  import './assets/css/bootstrap.min.css';
  import  './assets/css/main.css'
  ....

or in App.vue :

 <template>...</template>
 <script>...</script>
 <style src='./assets/css/bootstrap.min.css'></style>
 <style src='./assets/css/main.css'></style>

Using the vue-cli v4, go to your main.js file and add the imports of your js/css files like this

import './assets/main.js'
import './assets/main.css'

And make sure you have put those file in the assets folder of your project!

发布评论

评论列表(0)

  1. 暂无评论