如何在vue && webpack 项目中的单文件组件中引入css?

  引入方式很简单,就是在script下使用require()即可。 因为import 是import。。。from 的形式,所以是不需要的。

<script>
  import {mapState, mapMutations} from "vuex"
  import DetailItem from "@components/detail"
  require('../assets/css/swiper-3.4.1.min.css')

  export default {
    components: {
      DetailItem

  这样的好处在于只在这一个组件中使用,那么就在这一个组件中加载 。

  如果不用这种方式,我们也可以使用在index.html中加载cdn的方式,但是这种方式的缺点是很明显的,在进入首页时,我们并不需要他,但是却阻塞了页面的加载,影响性能。