How to include css files in Vue 2

后端 未结 4 1618
囚心锁ツ
囚心锁ツ 2020-12-01 03:00

I\'m new to vue js and trying to learn this. I installed a fresh new version of vue webpack in my system. I\'m having a css, js and images of this a theme template which I w

4条回答
  •  囚心锁ツ
    2020-12-01 03:06

    If you want to append this css file to header you can do it using mounted() function of the vue file. See the example.
    Note: Assume you can access the css file as http://www.yoursite/assets/styles/vendor.css in the browser.

    mounted() {
            let style = document.createElement('link');
            style.type = "text/css";
            style.rel = "stylesheet";
            style.href = '/assets/styles/vendor.css';
            document.head.appendChild(style);
        }
    

提交回复
热议问题