Skip to content
Advertisement

Vue split components from a single .js file in multiple files

I have created a component inside my index.js (where my main Vue code is). Now I would like to modularize the project and put the component into a separate file. I don’t know how to do that because if I create e.g. optionalapm.js the main index.js returns an error that it can’t locate the vue component optionalapm which I included.

How can I import the component into the index.js?

Here’s my code of the component:

JavaScript

And that’s the relevant code in the index.js:

JavaScript

Advertisement

Answer

You should use Single File Components, as described in the documentation. Next to it, read this useful blog post about using SFC’s.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement