【问题标题】:How to import css file from node_modules in Vue-component如何从 Vue-component 中的 node_modules 导入 css 文件
【发布时间】:2018-05-02 02:54:47
【问题描述】:

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

我的组件.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>

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

【问题讨论】:

标签: css webpack vue.js vuejs2 vue-component


【解决方案1】:

正如@LinusBorg 在vue-loader 讨论线程中建议的here,您可以在&lt;style&gt;-tag 中使用src-attribute:

我的组件.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>

【讨论】:

  • 是的,它的工作:
  • 应该也可以在没有 node_modules 的情况下使用 toast-ui/editor/dist/toastui-editor.css。
猜你喜欢
  • 2017-04-29
  • 2018-10-01
  • 2019-10-01
  • 2020-08-08
  • 2021-07-17
  • 1970-01-01
  • 2018-08-06
  • 1970-01-01
  • 2018-05-07
相关资源
最近更新 更多