如何从Vue组件中的node_modules导入css文件

Pet*_*sev 4 css webpack vue.js vue-component vuejs2

我想将此toastr -library连接到我的组件中:

我的component.vue

<script>
  import toastr from 'toastr';

  export default {
    mounted(){
      toastr.success('Hello from toastr!');
    }
  }
</script>

<template>
  <div>
    Template for my-component.vue here.
  </div>
</template>


<style>
  /* HOW TO IMPORT `toastr.css` FROM NODE_MODULES HERE?
</style>
Run Code Online (Sandbox Code Playgroud)

如何从 node_modules 目录连接库的 css?

hed*_*din 11

作为@LinusBorg建议这里的VUE装载机话题,您可以使用src-attribute内<style>-标签:

我的component.vue

<script>
  import toastr from 'toastr';

  export default {
    mounted(){
      toastr.success('Hello from toastr!');
    }
  }
</script>

<template>
  <div>
    Template for my-component.vue here.
  </div>
</template>


<style src='toastr/build/toastr.min.css'></style>
Run Code Online (Sandbox Code Playgroud)