Miss any of our Open RFC calls?Watch the recordings here! »

vue-loader-subcomponent

3.0.1 • Public • Published

vue-loader-subcomponent

Basic Usage

A subcomponent loader for vue-loader that allows the following extension:

<!-- 
  <list-title> subcomponent 
-->
<subcomponent name="list-title">
  <template>
      <h1>List Title</h1>
  </template>
</subcomponent>
 
<!-- 
  <list-item> subcomponent 
-->
<subcomponent name="list-item">
  <template>
      <li><a :href="item.href">{{item.text}}</a></li>
  </template>
  <script>
    export default {
      props: ['item']
    };
  </script> 
</subcomponent>
 
 
<!-- 
   Main component as usual 
-->
<template>
  <div>
    <list-title />
    My fancy list:
    <ul>
      <list-item v-for="item in items" :item="item" />
    </ul>
  </div>
</template>
<script>
  export default {
    data() {
      return { items: [
          { href: "#", text: "index" },
      ]};
    }
  };
</script> 

Configuration

You have to edit your webpack.config.js to:

// ...
module: {
  rules: [
    // ...,
    {
      test: /\.vue$/,
      use: ['vue-loader-subcomponent', {
        loader: 'vue-loader',
        options: {
          loaders: {
            subcomponent: 'vue-loader-subcomponent/subcomponent'
          }
        }
      }]
    }
  ]
}
 

So the vue-loader can recognize the subcomponent extension

Install

npm i vue-loader-subcomponent

DownloadsWeekly Downloads

1

Version

3.0.1

License

ISC

Last publish

Collaborators

  • avatar