How to load external CSS in Vue

痴心易碎 提交于 2021-01-24 11:55:05

问题


I have created a Vue project with Typescript having components in class style. I need to include some external CSS file - like from Amazon S3. The CSS doesn't seems to be loaded.

In the network section I can see it.


回答1:


you can load external URL

<style lang="scss or less">
    @import "https://external_url_.css";
    @import ".../assest/_.css";
</style>

you can load css loaders installed if you more such as sass-loader, css-loader , less-loader npm




回答2:


I suggest you to use preprocessor

Install SASS -

npm install -D sass-loader sass

then You will be able to import it in your App.vue

<style lang="scss">
@import './static/css/style.css';
</style>

Update

I figured out one more way to include single css file.

In your App.vue, you can add css file to style src

<style src="relative-path/style.css"></style>


来源:https://stackoverflow.com/questions/57686219/how-to-load-external-css-in-vue

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