I'm wondering if there is a way to split a Single File Components file into multiple smaller ones.
What am I talking about? Let's look at this:
<template>
...
</template>
<script>
export default {
name: 'my-component',
};
</script>
<style scoped>
...
</style>
That is the way the typical vue.js single file component is built up. As you can see, there is a html
-section (content of <template>
tag), a javascript
-section (content of <script>
tag) and a css
-section (content of style
tag). I was wondering if it is possible to split all of those sections into single files. Let's call them my-component.css
, my-component.es6
and my-component.html
- all 'belonging' to my-component.vue
.
I managed to extract the javascript and the css styling into standalone files like so:
<template>
...
</template>
<script src="./my-component.es6"></script>
<style scoped>
@import './my-component.css';
</style>
This works just fine. Now I'm just left with the html
-section. Is there a way to extract this one also?
Why?
I like to have a clear code separation and this is the only way to keep the 'code-mixing' to a minimum within the my-component.vue
file.