script import in the wrong order, function not defined

2

I have a component vue ( Map.vue ):

<template>
...
</template>

<script>
import '../../assets/js/map.js'

export default {
    name: 'home',
    data () {
        return {
            init_data: {},
        }
    },
    created: function() {
         this.init_data = window.get_init_data(this.view, function(response) {
               document.title = response.body.page_title;
               init_map(some_arguments); // erro aqui
         });
    }
}
</script>

map.js:

const key = ******;
function init_map(some_args) {
    ...
}

Error:

  

[Vue Warn]: Error in created hook: "ReferenceError: init_map is not   defined "

And in fact, by inspecting the source code the function is being called before its signature.

Note: I do not want to include map.js in my webpack entries because I will only need this script in a component.

    
asked by anonymous 29.06.2017 / 13:50

1 answer

2

I ended up getting it done:

Map.vue:

<script>
import init_map from '../../assets/js/map.js';
...
</script>

map.js

const key = ******;
export default function init_map(some_args) {
    ...
}
    
29.06.2017 / 18:01