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

时间:2017-11-18 11:52:52

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

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

MY-component.vue

<content:encoded>
        <![CDATA[
        <!doctype html>
        <html lang="en" prefix="op: http://media.facebook.com/op#">
          <head>
            <meta charset="utf-8">
            <link rel="canonical" href="http://example.com/article.html">
            <meta property="op:markup_version" content="v1.0">
          </head>
          <body>
            <article>
              <header>
                <!— Article header goes here -->
              </header>

              <!— Article body goes here -->

              <footer>
                <!— Article footer goes here -->
              </footer>
            </article>
          </body>
        </html>
        ]]>
      </content:encoded>

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

1 个答案:

答案 0 :(得分:4)

@LinusBorg在vue-loader讨论主题中建议here时,您可以使用src - <style>内的属性 - 标记:

MY-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>