VUE CLI 3 - How to import scripts and styles

落花浮王杯 提交于 2020-02-01 04:41:26

问题


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" />


回答1:


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>


来源:https://stackoverflow.com/questions/52671245/vue-cli-3-how-to-import-scripts-and-styles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!