在 Vuejs 中拥有全局 css 的最佳方式 [英] Best way to have global css in Vuejs

查看:55
本文介绍了在 Vuejs 中拥有全局 css 的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Vuejs 中为所有组件创建全局 css 文件的最佳方法是什么?(默认 css,如 bg 颜色、按钮样式等)

What is the best way to have a global css file in Vuejs for all components? (Default css like bg color, button styling, etc)

  • 在 index.html 中导入一个 css 文件
  • 在主组件中做@import
  • 将所有 css 放在主组件中(但这将是一个巨大的文件)

推荐答案

在你的 index.html 中导入 css,但是如果你使用 webpack,你可以在你的主 js 配置中导入你的样式表,你的所有组件都会得到

Import css in your index.html, but if you're using webpack you can just import your stylesheets in your main js config and all your components will get the css.

如果使用 webpack 将其添加到 main.js 中,则建议如下评论:

As comments below suggested if using webpack adding this to main.js works:

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

这篇关于在 Vuejs 中拥有全局 css 的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆