Include external CSS library in only one Vue component

10,232

Import css file in style tag of App.js

<style>
@import './static/css/style.css';
</style>
Share:
10,232
Linx
Author by

Linx

Updated on August 04, 2022

Comments

  • Linx
    Linx almost 2 years

    I have a Vue app with many components. Currently I have Font-Awesome included in the head of the index.html file however only ONE page, or component, actually needs it. Is it possible to move it to the component itself so that it only loads when it's needed?

    MOVE THIS

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    

    TO THIS

    <template></template>
    <link rel="stylesheet" href="../../static/css/font-awesome-4.7.0/css/font-awesome-min.css"></link>
    <script>
        export default {
            name: 'SingleComponent',
            data: function() {
                return{}
            }
        }
    </script>
    <style scoped>
    </style>
    

    I've tried downloading Font-Awesome and adding a link tag in the component like above ^^^^ I don't get any errors but the icons still don't work.

  • Linx
    Linx over 6 years
    No I have many components but only one that needs Font-Awesome
  • Hybrid web dev
    Hybrid web dev almost 5 years
    This isn't an answer.