Reputation: 67
I built my project with the Vue CLI. I am not expert with vue, still learning. So I need help because I can not solve one problem. First I wanted to separate script part of the SFC which I menaged to do. In SvgMap.vue component I wrote:
<script src="../js/SvgMap.js"></script>
and my code in separate file SvgMap.js is working fine.
The problem is when I want to separate my code in SvgMap.js in different javascript files. I dont know how to include them all in the vue component. Is this actually possible?
In my project I use javascript to generate a lot of data from svg map component (coordinates, text, colors...) which I want to be in separate files. The data will be leter used in other component from vuex library.
Upvotes: 0
Views: 695
Reputation: 39
What you want to do, is to split up your code into different files.
From these files, you'll need to export the parts that you need in your SvgMap.js
.
In your SvgMap.js
you just need to import the exports and you're good to go.
Here is an example:
export.js
export function addNumbers(a,b){
return a+b
}
main.js
import { addNumbers } from './path/to/export.js'
console.log(addNumbers(1,2))
Upvotes: 1